Changes between Version 11 and Version 12 of user-examples


Ignore:
Timestamp:
Feb 13, 2011 11:05:14 AM (9 years ago)
Author:
stefan
Comment:

reflect changes due to use of pkg-config; replace COIN by COIN-OR; fix link to MSVC project; remove link to abandoned page

Legend:

Unmodified
Added
Removed
Modified
  • user-examples

    v11 v12  
    1 = Linking your Code with COIN Libraries =
     1= Linking your Code with COIN-OR Libraries =
    22
    3 Again, 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.
     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/MSVisualStudio here] for more information.
    44
    5 Assume that you have dowloaded the COIN package {{{Pkg}}}
    6 in the directory {{{Coin-Pkg}}}. You have run {{{configure}}}, {{{make}}}, and {{{make install}}} in
    7 the directory {{{Coin-Pkg/build}}}. Assume that you used {{{Coin-Pkg/build}}} as
    8 the install directory (i.e. the default), obtaining libraries
    9 in {{{Coin-Pkg/build/lib}}} and include files in {{{Coin-Pkg/build/include}}}.
     5Assume that you have [wiki:user-download downloaded] the COIN-OR package {{{Pkg}}} in the directory {{{Coin-Pkg}}}.
     6You have run [wiki:user-configure configure], [wiki:user-compile make, and make install] in the directory {{{Coin-Pkg/build}}}.
     7Assume that you used {{{Coin-Pkg/build}}} as the install directory (i.e. the default), obtaining libraries in {{{Coin-Pkg/build/lib}}} and include files in {{{Coin-Pkg/build/include/coin}}}.
    108
    11 For most COIN packages, the main directory contains an {{{examples}}}
    12 subdirectory. Assuming that this is the case for the package {{{Pkg}}}, the directory {{{Coin-Pkg/build/Pkg/examples}}}
    13 contains a {{{Makefile}}} that  has been adapted to your system.
    14 If you want to hook up your own code to this COIN library, it might be a good idea to start by looking at the example Makefile.
     9For most COIN-OR packages, the main directory contains an {{{examples}}} subdirectory.
     10Assuming that this is the case for the package {{{Pkg}}}, the directory {{{Coin-Pkg/build/Pkg/examples}}} contains a {{{Makefile}}} that has been adapted to your system.
     11If you want to hook up your own code to this COIN-OR library, it might be a good idea to start by looking at the example Makefile.
    1512
    16 {{{Note:}}}  You should use only the libraries and header files that have been installed in {{{Coin-Pkg/build/lib}}} and {{{Coin-Pkg/build/include}}}
    17 not those in any other directory.  Picking up libraries and headers from the source directories has a good chance of creating problems.
     13{{{Note:}}}  You should use only the libraries and header files that have been installed in {{{Coin-Pkg/build/lib}}} and {{{Coin-Pkg/build/include/coin}}}, not those in any other directory.  Picking up libraries and headers from the source directories has a good chance of creating problems.
    1814
    1915In order to modify {{{examples/Makefile}}} to compile your own code, you usually only have to change the first part, which might look like this:
     
    3531
    3632# CHANGEME: Additional libraries
    37 ADDLIBS = -L$(HOME)/MyLibrariesDir -ladditinal_lib
     33ADDLIBS = -L$(HOME)/MyLibrariesDir -ladditional_lib
    3834
    3935# CHANGEME: Additional flags for compilation (e.g., include flags)
     
    5248 * '''OBJS''' should be set to the list of '''all object files''' that correspond to the source files you want to compile.
    5349
    54  * '''ADDLIBS''' should list '''additonal compiler link flags''' to link with (non-COIN) libraries required to link your final program.
     50 * '''ADDLIBS''' should list '''additonal compiler link flags''' to link with (non-COIN-OR) libraries required to link your final program.
    5551
    56  * '''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.
     52 * '''ADDINCFLAGS''' should be set to compiler flags that tell it where to look for '''additional (non-COIN-OR) header files''' required to compile your code - if required.
    5753
    5854 * '''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.)
     
    6763##########################################################################
    6864
     65COIN_HAS_PKGCONFIG = TRUE
     66COIN_CXX_IS_CL = #TRUE
     67
    6968# C++ Compiler command
    7069CXX = g++
    7170
    7271# C++ Compiler options
    73 CXXFLAGS = -O3 -fomit-frame-pointer -pipe -DNDEBUG  -pedantic-errors \
    74       -Wimplicit -Wparentheses -Wreturn-type -Wcast-qual -Wall \
    75       -Wpointer-arith -Wwrite-strings -Wconversion
     72CXXFLAGS = -O3 -pipe -DNDEBUG -pedantic-errors -Wimplicit -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -Wno-unknown-pragmas 
    7673
    7774# additional C++ Compiler options for linking
    78 # Don't add rpath if you want to have rpms built from your package,
    79 # since many distributions forbid it.
    8075CXXLINKFLAGS =  -Wl,--rpath -Wl,/home/me/Coin-Pkg/lib
    8176
    82 # Directory with COIN header files
    83 COININCDIR = /home/me/Coin-Pkg/include
     77# C Compiler command
     78CC = gcc
    8479
    85 # Directory with COIN libraries
    86 COINLIBDIR = /home/me/Coin-Pkg/lib
     80# C Compiler options
     81CFLAGS = -O3 -pipe -DNDEBUG -pedantic-errors -Wimplicit -Wparentheses -Wsequence-point -Wreturn-type -Wcast-qual -Wall -Wno-unknown-pragmas 
    8782
    88 # Directory with directories with addlibs files
    89 COINSHAREDIR = /home/me/Coin-Pkg/share/doc/coin
     83# Include directories (we use the CYGPATH_W variables to allow compilation with Windows compilers)
     84ifeq ($(COIN_HAS_PKGCONFIG), TRUE)
     85  INCL = `PKG_CONFIG_PATH=/home/me/Coin-Pkg/lib/pkgconfig:/usr/bin/pkg-config --cflags pkg`
     86else
     87  INCL = [...]
     88endif
     89INCL += $(ADDINCFLAGS)
    9090
    91 # Libraries necessary to link with Clp
    92 LIBS = -L$(COINLIBDIR) -lCbc -lCgl -lOsiClp -lOsiCbc -lOsi -lClp -lCoinUtils \
    93          \
    94         `cat $(COINSHAREDIR)/Cgl/cgl_addlibs.txt` \
    95         `cat $(COINSHAREDIR)/Osi/osi_addlibs.txt` \
    96         `cat $(COINSHAREDIR)/Clp/clp_addlibs.txt` \
    97         `cat $(COINSHAREDIR)/CoinUtils/coinutils_addlibs.txt`
    98 
    99 # Necessary Include dirs (we use the CYGPATH_W variables to allow
    100 # compilation with Windows compilers)
    101 INCL =  -I`$(CYGPATH_W) $(COININCDIR)` $(ADDINCFLAGS)
     91# Linker flags
     92ifeq ($(COIN_HAS_PKGCONFIG), TRUE)
     93  LIBS = `PKG_CONFIG_PATH=/home/me/Coin-Pkg/lib/pkgconfig:/usr/bin/pkg-config --libs pkg`
     94else
     95  ifeq ($(COIN_CXX_IS_CL), TRUE)
     96    LIBS = /link /libpath:`$(CYGPATH_W) /home/me/Coin-Pkg/lib` libPkg.lib  [...]
     97  else
     98    LIBS = -L/home/me/Coin-Pkg/lib -lPkg  [...]
     99  endif
     100endif
    102101
    103102# The following is necessary under cygwin, if native compilers are used
     
    111110        bla=;\
    112111        for file in $(OBJS); do bla="$$bla `$(CYGPATH_W) $$file`"; done; \
    113         $(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla $(ADDLIBS) $(LIBS)
     112        $(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla $(LIBS) $(ADDLIBS)
    114113
    115114clean:
     
    130129        $(CC) $(CFLAGS) $(INCL) -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi`
    131130}}}
     131The variables '''COIN_HAS_PKGCONFIG''' and '''COIN_CXX_IS_CL''' are setup by configure and should '''not be changed''' by the user.
    132132
    133 The '''compiler name''' variables '''CXX''', '''CC''' and '''F77''' will already be adapted to your system, as well as the corresponding variables '''CXXFLAGS''', '''CFLAGS''', '''FFLAGS''' 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 the same (or compatible) options.
     133The '''compiler name''' variables '''CXX''', '''CC''' and '''F77''' will already be adapted to your system, as well as the corresponding variables '''CXXFLAGS''', '''CFLAGS''', '''FFLAGS''' for the '''compiler flags'''.  Those are the same that have been used to compile the COIN-OR library, and it is probably not a bad idea to choose the same (or compatible) options.
    134134
    135135The '''COININCDIR''' and '''COINLIBDIR''' is adapted to the '''directories where the COIN header files and libraries have been installed'''.
    136136
    137 If 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 shared libraries''' into the executables (if that is supported on your system).  Alternatively, you can set the {{{LD_LIBRARY_PATH}}} or similarly names environment variable to point to the directory with the COIN shared object.
     137If you compiled the COIN-OR library as a shared object, the '''CXXLINKFLAGS''' is set to the compiler link flag that hardcodes '''the search path to the installed shared libraries''' into the executables (if that is supported on your system).  Alternatively, you can set the {{{LD_LIBRARY_PATH}}} or similarly names environment variable to point to the directory with the COIN-OR shared object.
    138138
    139 The '''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 $(COINSHAREDIR)/*/*_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 subdirectories of the share/doc/coin directory.
     139The '''INCL''' variable is set to the '''compiler flags that are required to find the header files of the COIN-OR library'''. If {{{pkg-config}}} is available, then it is used to read the compiler flags from the pkg.pc file.
     140If {{{pkg-config}}} is not available, then the configure script sets up a list of compiler flags to locate the installed header files of a project and all it's dependencies. Since in this example pkg-config is available, the corresponding flags are not setup by configure. Otherwise they would replace the {{{[...]}}}.
     141
     142The '''LIBS''' variable is set to the '''compiler link flags that are required to link with the COIN-OR library'''. If {{{pkg-config}}} is available, then it is used to read the linker flags from the pkg.pc file.
     143If {{{pkg-config}}} is not available, then the configure script sets up a list of linker flags that correspond to all dependent libraries. Since in this example pkg-config is available, the corresponding flags are not setup by configure. Otherwise they would replace the {{{[...]}}}.
    140144
    141145The '''generic compilation rules''' (e.g., {{{.c.o}}}) might look somewhat complicated.  But with this, the Makefile can also be used by people who 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}}}, otherwise it is just "{{{echo}}}".
    142 
    143 Once your code builds and links correctly with Coin, you may want to consider distributing your code as part of Coin. [wiki:user-distribute This page] describes build-related issues you should consider when distributing code from Coin.