Changes between Initial Version and Version 1 of user-examples


Ignore:
Timestamp:
May 27, 2006 7:50:52 PM (15 years ago)
Author:
andreasw
Comment:

first draft

Legend:

Unmodified
Added
Removed
Modified
  • user-examples

    v1 v1  
     1= Linking your Code with COIN Libraries =
     2
     3Again, this information only pertains to UNIX-like systems, where you use {{{configure}}} and {{{make}}}.  If you want to use the MS Developer Studio, please check [http://projects.coin-or.org/MSDevStudio here] for more information.
     4
     5A number of COIN projects that generated libraries have an {{{examples}}} subdirectory.  After you run configure, you will find a simple {{{Makefile}}} in there, that  has been adapted to your system.  If you want to hook up your own code to this COIN library, it might be a good idea to start by looking at this Makefile.
     6
     7In order to modify this Makefile to compile your own code, you usually only have to change the first part, which might look like this:
     8
     9{{{
     10##########################################################################
     11#    You can modify this example makefile to fit for your own program.   #
     12#    Usually, you only need to change the five CHANGEME entries below.   #
     13##########################################################################
     14
     15# CHANGEME: This should be the name of your executable
     16EXE = my_prog
     17
     18# CHANGEME: Here is the name of all object files corresponding to the source
     19#           code that you wrote in order to define the problem statement
     20OBJS =  my_prog.o \
     21        additional_source1.o \
     22        additional_source2.o
     23
     24# CHANGEME: Additional libraries
     25ADDLIBS = -L$(HOME)/MyLibrariesDir -ladditinal_lib
     26
     27# CHANGEME: Additional flags for compilation (e.g., include flags)
     28ADDINCFLAGS = -I$(HOME)/MyCoolPrograms/include
     29
     30# CHANGEME: Directory to the sources for the (example) problem definition
     31# files
     32SRCDIR = .
     33VPATH = .
     34}}}
     35
     36The modification is pretty straightforward:
     37
     38 * {{{EXE}}} should be set to the name of the executable you want to compile with this Makefile.
     39
     40 * {{{OBJS}}} should be set to the list of all object files that correspond to the source files you want to compile.
     41
     42 * {{{ADDLIBS}}} should list additonal compiler link flags to link with (non-COIN) libraries required to link your final program.
     43
     44 * {{{ADDINCFLAGS}}} should be set to compiler flags that tell it where to look for additional (non-COIN) header files required to compile your code - if required.
     45
     46 * {{{SRCDIR}}} and {{{VPATH}}} should be set to the directory where your source code is.  (This allows you to compile your code with the Makefile in a different directory from the source code directory.)
     47
     48The lower part of the Makefiles looks somewhat like this:
     49
     50{{{
     51##########################################################################
     52#  Usually, you don't have to change anything below.  Note that if you   #
     53#  change certain compiler options, you might have to recompile Ipopt.   #
     54##########################################################################
     55
     56# C++ Compiler command
     57CXX = g++
     58
     59# C++ Compiler options
     60CXXFLAGS = -O3 -fomit-frame-pointer -pipe -DNDEBUG  -pedantic-errors -Wimplicit -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion
     61
     62# additional C++ Compiler options for linking
     63CXXLINKFLAGS =  -Wl,--rpath -Wl,/home/me/CoinStuff/lib
     64
     65# Directory with COIN header files
     66COININCDIR = /home/me/CoinStuff/include
     67
     68# Directory with COIN libraries
     69COINLIBDIR = /home/me/CoinStuff/lib
     70
     71# Libraries necessary to link with Clp
     72LIBS = -L$(COINLIBDIR) -lCbc -lCgl -lOsiClp -lOsiCbc -lOsi -lClp -lCoinUtils \
     73         \
     74        `cat $(COINLIBDIR)/cgl_addlibs.txt` \
     75        `cat $(COINLIBDIR)/osi_addlibs.txt` \
     76        `cat $(COINLIBDIR)/clp_addlibs.txt` \
     77        `cat $(COINLIBDIR)/coinutils_addlibs.txt`
     78
     79# Necessary Include dirs (we use the CYGPATH_W variables to allow
     80# compilation with Windows compilers)
     81INCL =  -I`$(CYGPATH_W) $(COININCDIR)` $(ADDINCFLAGS)
     82
     83# The following is necessary under cygwin, if native compilers are used
     84CYGPATH_W = echo
     85
     86all: $(EXE)
     87
     88.SUFFIXES: .cpp .c .o .obj
     89
     90$(EXE): $(OBJS)
     91        bla=;\
     92        for file in $(OBJS); do bla="$$bla `$(CYGPATH_W) $$file`"; done; \
     93        $(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla $(ADDLIBS) $(LIBS)
     94
     95clean:
     96        rm -rf $(EXE) $(OBJS)
     97
     98.cpp.o:
     99        $(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$<
     100
     101
     102.cpp.obj:
     103        $(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi`
     104
     105.c.o:
     106        $(CC) $(CFLAGS) $(INCL) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$<
     107
     108
     109.c.obj:
     110        $(CC) $(CFLAGS) $(INCL) -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi`
     111}}}
     112
     113The compiler name variables {{{CXX}}, {{{CC}}} and {{{F77}}} will already be adapted to your system, as well as the corresponding variables for the compiler flags.  Those are the same that have been used to compile the COIN library, and it is probably not a bad idea to choose similar (or compatible) options.
     114
     115The {{{COININCDIR}}} and {{{COINLIBDIR}}} will have been adapted to the directory where the COIN libraries have been installed.  (In the above example, it is assumed that you ran {{{configure}}} with the flag {{{--prefix=/home/me/CoinStuff}}}, so that the result of the COIN compilation was installed into subdirectories there.)
     116
     117If you compiled the COIN library as a shared object, the {{{CXXLINKFLAGS}}} is set to the compiler link flag that hardcodes the search path to the installed library into the executables (if that is supported on your system).  Alternatively, you can set the {{{LD_LIBRARY_PATH}}} or similarly to include the directory with the shared object.
     118
     119The {{{LIBS}}} variable is set to the compiler link flags that are required to link with the COIN library.  In the above example, it is the Cbc library.  Note the {{{`cat $(COINLIBDIR)/*_addlibs.txt`}}} entries --- when a COIN library might have additional library dependency (e.g., for the GNU package zlib), the corresponding compiler link flags are listed in the {{{*_addlibs.txt}}} file as a string.  These files are installed in the same location as the libraries.
     120
     121The generic compilation rules (e.g., {{{.c.o}}}) might look somewhat complicated.  But with this, the Makefile can also be used by people how work with the MS compilers (e.g., {{{cl}}}) under Cygwin, since those compilers don't understand the UNIX-type directory paths.  In such a case, the {{{CYGPATH_W}}} will have been set to {{{cygpath -w}}} by {{{configure}}}.