Programming and Graphics

(Kiana) #1

290 Introduction to C++ Programming and Graphics


Compilation makefile


A Linux makefile that compiles the C++ filesapouni.ccand produces
the executablesapounireads:


LIB1 = -leng -lmx -lut -licuuc -licuio
LIB2 = -lmat -licudata -licui18n -lMTwister
LIB3 = -I/usr/local/matlab/extern/include
LIB4 = -L/usr/local/matlab/bin/glnx86
mexec: mexec.cc
c++ -o sapouni sapouni.cc $(LIB1) $(LIB2) $(LIB3) $(LIB4)

The first four lines define libraries and header files participating in the exe-
cutable. We see that nine libraries must be linked with the C++ object of our
code, accompanied by corresponding header files. To produce the executable,
we issue the command


make mexec

Library path


A system environmental variable permeates all processes to define the
values of important system parameters. Examples are the executable search
path, the choice of a display device, and a printer’s name or address. The envi-
ronmental variable LDLIBRARYPATH tells the linker where to find libraries
not found in standard system directories.


For the compiled programsapounito run, the environmental variable
LDLIBRARYPATHmust be set properly. Assume thatMatlabhas been in-
stalled in the directory/usr/local/matlab. In the Unix tcsh shell, we issue
the command:


setenv LDLIBRARYPATH ’/usr/local/matlab/bin/glnx86’

In the Unix bash shell, we issue the command:


export LDLIBRARYPATH=’/usr/local/matlab/bin/glnx86’

In other systems, this variable can be set through a graphical user interface.


9.3 TheMatlabengine functions


C++ communicates withMatlabthrough a small number ofenginefunctions.
AMatlabsession invoked from C++ is identified by a pointer declared as


Engine * ep;
Free download pdf