fois fois - 6 months ago 17
Linux Question

How can I link boost library on cluster?

I have program which works well on my computer with following command

g++ -o result source.cpp -lboost_program_options


However, this command doesn't work on the cluster where the boost library is such



#%Module1.0#####################################################################
##
## boost modulefile
##
## boost/1.55.0/gcc-4.4.7
##
proc ModulesHelp { } {
puts stderr "\tThis module loads boost-1.55.0 environment for aries compute nodes."
puts stderr ""
puts stderr "\tBuild script: /build/gcc-4.4.7/build-boost-1.55.0.sh"
puts stderr "\tCompilation options: /build/gcc-4.4.7/BUILD-boost-1.55.0/boost/bbost.v2/config.log"
}
module-whatis "loads the boost environment for x86_E5v2 CNs"

module load mvapich2/2.0.1/gcc-4.4.7 python/2.7.9/gcc-4.4.7
conflict boost

# for Tcl script use only
set version 1.55.0
set root /ssoft/boost/1.55.0/RH6/gcc-4.4.7/x86_E5v2/mvapich2

setenv BOOST_ROOT "${root}"
setenv BOOST_INCLUDE "${root}/include"
setenv BOOST_LIBRARY "${root}/lib"
prepend-path LD_LIBRARY_PATH "${root}/lib"


I have searched how to solve this problem for a while, but haven't found one works for me.

Thank you.

Answer

You need to specify the path to where the compiler can find the include files and libraries, since they're installed in a non-default path.

Most likely something like this, after loading the module for boost (that's "minus capital i" for include files and "minus capital L" for libraries):

g++ -o result source.cpp -I$BOOST_INCLUDE -L$BOOST_LIBRARY -lboost_program_options

Alternatively, you can update the $CPATH and $LIBRARY_PATH environment variables (actually, the module file should probably be doing that for you):

export CPATH=$BOOST_INCLUDE:$PATH
export LIBRARY_PATH=$BOOST_LIBRARY:$LIBRARY_PATH
g++ -o result source.cpp -lboost_program_options