
5.2.2 Compile the Example Source Code
Referring again to Listing 1 and following the steps in Section 4.4 an instruction for
compiling and linking the example in Section 5.2 is given below:
(i) Convert M-Files to C and create a library:
mcc -v -t -W lib:libsimple -L C -T link:lib -h -c
libmmfile.mlib simple.m
gcc -c -fPIC -I$(INCL) $(CFLAGS) $(SRCS)
gcc $(LDFLAGS) -shared -o libsimple.so $(OBJS) $(LD LIB S)
(ii) Compile C main source file and link it to library:
gcc -c -I$(INCL) $(CFLAGS) main.c
gcc $(LDFLAGS) -o example main.o -lsimple $(LDLIBS)
Annotation
(ii) After the main file was compiled, it is linked to the created library libsimple as well
to the origin MATLAB Libraries. If you didn’t copy your library into a directory
the linker will find it, you have to add a –rpath-link as well as a -L option for the
parent directory of your library.
5.3 Compile a Converted C Program on an Other Machine
(i) Make a package containing the MATLAB include files and the MATLAB libraries
described in Section 4.2, the C source code generated by mcc, any MEX-files that
are needed and the mglinstaller.
(ii) Write a Makefile referencing to the MATLAB include files and libraries. To deter-
mine the libraries you have to link with your library call mmc in the verbose and
debug mode(see: Section 4.3). To determine the libraries you have your C-program
to link with call mbuild (see: Section 2.5).
(iii) Compile and link your library using the compiler and linker settings of
Section 4.3.
(iv) Run the mglinstaller.
(v) Add the directory matlab rt dir/bin/glnx86 created by the mglinstallerto the
LD LIBRARY PATH environment variable as well as the parent path of your own
MATLAB libraries.
16
Kommentare zu diesen Handbüchern