Boost logo

Boost Interest :

Subject: Re: [Boost-cmake] Building boost "with an uninstalled build" and linking to boost libs
From: Nehme Bilal (nbilal_at_[hidden])
Date: 2010-03-24 12:27:20


Hello,

The following is in boost "getting started" documentation:

Auto-Linking
Most Windows compilers and linkers have so-called
“auto-linking support,” which eliminates the second
challenge. Special code in Boost header files detects your
compiler options and uses that information to encode the
name of the correct library into your object files; the
linker selects the library with that name from the
directories you've told it to search.

when you build your visual studio boost project created
with cmake, libboost_filesystem-vc-mt-sgd-1_41.lib is
created instead of
libboost_filesystem-vc90-mt-sgd-1_41.lib. (see
boostBuild/lib) directory.

Now when you try to build a project that use boost,
because of the special code in boost header files, visual
studio will try to find
libboost_filesystem-vc90-mt-sgd-1_41.lib instead of
libboost_filesystem-vc-mt-sgd-1_41.lib

so I think that boost-cmake is not naming the libs
correctly for visual studio.

Nehme

On Wed, 24 Mar 2010 09:31:36 -0500
  Brian Davis <bitminer_at_[hidden]> wrote:
> I am currently trying the boost "With an uninstalled
>build" variety:
>
>
> # Boost Related
> SET( BOOST_LIB_INSTALL_DIR ${BUILD_DIR}/ouput/lib CACHE
>STRING "" FORCE )
> SET( BOOST_EXPORTS_INSTALL_DIR ${BUILD_DIR}/ouput/lib
>CACHE STRING "" FORCE
> )
> SET( BOOST_INCLUDE_INSTALL_DIR
>${BUILD_DIR}/ouput/include CACHE STRING ""
>FORCE )
> #SET( BUILD_PROJECTS NONE CACHE STRING "" FORCE )
> SET( BUILD_PROJECTS thread filesystem CACHE STRING ""
>FORCE )
>
> add_subdirectory(
>${THIRD_PARTY_SRC_DIR}/boost-cmake-1_41_0 ./boost )
>
> reading:
> http://sodium.resophonic.com/boost-cmake/current-docs/exported_targets.htmlI
> find:
>
> --snip--
> Example¶
>
> There is an unpacked boost in
>/home/troy/boost-1.41.0/src and built boost in
> directory /home/troy/boost/1.41.0/build. I have a
>program that builds from
> one file, main.cpp and uses boost threads. My
>CMakeLists.txt looks like
> this:
>
> include_directories(
> /home/troy/boost-1.41.0/src
> /home/troy/boost-1.41.0/build/lib/Exports.cmake
> )
>
> add_executable(my_program main.cpp)
>
> target_link_libraries(my_program
>boost_thread-mt-shared-debug)
>
> --end snip--
>
> The part I don't like was the
>boost_thread-mt-shared-debug where
> -share-debug needed to be specified. What if I switch
>to release?
>
>
> When I try to link some boost libs to a test app:
>
>
> TARGET_LINK_LIBRARIES( ${SQUARE_ME_TEST_APP}
> ${MATLAB_CUDA_MEX_NAME}
> ${Boost_FILESYSTEM_LIBRARY}
> ${Boost_SYSTEM_LIBRARY}
> # boost_filesystem-mt-shared-debug
> # boost_filesystem
> )
>
> 3>Linking...
> 3>LINK : fatal error LNK1104: cannot open file
> 'libboost_filesystem-vc90-mt-sgd-1_41.lib'
>
> Now except for hte 'lib" preceeding
> 'libboost_filesystem-vc90-mt-sgd-1_41.lib' as only:
>
> boost_filesystem-vc90-mt-sgd-1_41.lib
> boost_filesystem-vc90-mt-gd-1_41.lib
>
> are build on my Win64 system which I am sure is a result
>of
> ${Boost_FILESYSTEM_LIBRARY}
>
> What is the best way to link to boost libs? Except for
>the point what did
> I miss? :-) I am sure it has something to do with (from
> http://sodium.resophonic.com/boost-cmake/current-docs/exported_targets.html
> ):
>
>
> -snip-
> The problem here is that the real name of the
>multithreaded, shared, debug
> library target is boost_thread-mt-shared-debug. I know
>this is confusing;
> much of this is an attempt to be compatible with
>boost.build.
>
> If you are having trouble, have a look inside that file
>Exports.cmake. For
> each available target, you’ll see:
>
> # Create imported target boost_thread-mt-shared-debug
> ADD_LIBRARY(boost_thread-mt-shared-debug SHARED
>IMPORTED)
>
> # Import target "boost_thread-mt-shared-debug" for
>configuration "Release"
> SET_PROPERTY(TARGET boost_thread-mt-shared-debug APPEND
>PROPERTY
> IMPORTED_CONFIGURATIONS RELEASE)
> SET_TARGET_PROPERTIES(boost_thread-mt-shared-debug
>PROPERTIES
> IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE "pthread;rt"
> IMPORTED_LOCATION_RELEASE
> "/home/troy/Projects/boost/cmake/cmaketest/build/boost/lib/libboost_thread-mt-d.so.1.41.0"
> IMPORTED_SONAME_RELEASE
>"libboost_thread-mt-d.so.1.41.0"
> )
>
> it is the name in the ADD_LIBRARY line that you pass to
> target_link_libraries().
>
> -end snip-
>
> my exports.cmake file (in trunk\build\dvip4-Win64\lib)
>shows:
>
> -snip-
> # Create imported target boost_thread-mt-shared
> ADD_LIBRARY(boost_thread-mt-shared SHARED IMPORTED)
>
> # Import target "boost_thread-mt-shared" for
>configuration "Debug"
> SET_PROPERTY(TARGET boost_thread-mt-shared APPEND
>PROPERTY
> IMPORTED_CONFIGURATIONS DEBUG)
> SET_TARGET_PROPERTIES(boost_thread-mt-shared PROPERTIES
> IMPORTED_IMPLIB_DEBUG
> "C:/projects/NIH2009/source/branches/trunk/build/dvip4-Win64/lib/Debug/boost_thread-vc90-mt-1_41.lib"
> IMPORTED_LOCATION_DEBUG
> "C:/projects/NIH2009/source/branches/trunk/build/dvip4-Win64/bin/Debug/boost_thread-vc90-mt-1_41.dll"
> )
>
> # Import target "boost_thread-mt-shared" for
>configuration "Release"
> SET_PROPERTY(TARGET boost_thread-mt-shared APPEND
>PROPERTY
> IMPORTED_CONFIGURATIONS RELEASE)
> SET_TARGET_PROPERTIES(boost_thread-mt-shared PROPERTIES
> IMPORTED_IMPLIB_RELEASE
> "C:/projects/NIH2009/source/branches/trunk/build/dvip4-Win64/lib/Release/boost_thread-vc90-mt-1_41.lib"
> IMPORTED_LOCATION_RELEASE
> "C:/projects/NIH2009/source/branches/trunk/build/dvip4-Win64/bin/Release/boost_thread-vc90-mt-1_41.dll"
> )
>
> -end snip-
>
> but NO boost_filesystem which I presume has to do with:
>
> SET( BUILD_PROJECTS thread filesystem CACHE STRING ""
>FORCE )
>
> and the text:
>
> -snip-
> BUILD_PROJECTS¶
>
> This is a semicolon-separated list of projects to be
>built, or "ALL" (the
> default) for all projects, or "NONE". Projects not
>appearing in this list
> (if list not "ALL") are ignored; no targets in this
>project will appear.
> Example:
>
> BUILD_PROJECTS=thread;python
> -end snip-
>
> I also tried
>
> SET( BUILD_PROJECTS "thread;filesystem" CACHE STRING ""
>FORCE )
>
> Do I need to even specify BUILD_PROJECTS or is there a
>way to specify the
> dependency in either add_dependencies or in
>target_link_libraries? This may
> sound crazy, but a build system that supports a syntax
>of dependency
> checking and building only what I need. From what I can
>tell at the moment
> with my current level of understanding of CMake... CMake
>really sucks at
> this. Let me be clear
>
>
> SET(SQUARE_ME_TEST_APP squaremetest )
> ADD_EXECUTABLE( ${SQUARE_ME_TEST_APP} square_me_test.cpp
>)
>
>
> SET( BOOST_DEPS system filesystem )
>
> find_package( Boost REQUIRED COMPONENTS system
>filesystem NO_MODULE )
>
> MESSAGE( "Boost_FILESYSTEM_LIBRARY = "
>${Boost_FILESYSTEM_LIBRARY} )
>
> TARGET_LINK_LIBRARIES( ${SQUARE_ME_TEST_APP}
> ${MATLAB_CUDA_MEX_NAME}
> ${Boost_FILESYSTEM_LIBRARY}
> ${Boost_SYSTEM_LIBRARY}
> # boost_filesystem-mt-shared-debug
> # boost_filesystem
> )
>
>
> #ADD_DEPENDENCIES( ${SQUARE_ME_TEST_APP}
>boost-cmake-1_41_0 )
> ADD_DEPENDENCIES( ${SQUARE_ME_TEST_APP} boost_filesystem
>)
>
> --
> Brian J. Davis


Boost-cmake list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk