---------- Forwarded message ---------- From: Forest Yang <[email protected]> Date: Tue, Jan 10, 2012 at 10:14 PM Subject: Re: [CMake] error of mixed dynamic/static link to Boost in windows VS2008 To: Mateusz Loskot <[email protected]>
On Fri, Jan 6, 2012 at 5:30 AM, Mateusz Loskot <[email protected]> wrote: > On 6 January 2012 05:30, Forest Yang <[email protected]> wrote: >> I am writing a library using boost_regex. For the unit test part, I >> am using boost_unit_test_framework and needs to be dynamical linked. >> Everything worked great on Linux but not the Windows VS 2008. >> >> I used the BoostPro binary installer, got boost components like: >> boost_regex-vc90-mt-gd-1_47.dll and .lib, also the >> libboost_regex-vc90-mt-gd-1_47.lib file. After the FIND_PACKAGE(Boost >> Components ...) I got the boost_*-vc90-mt-gd-1_47.lib version, (no >> prefix lib), however, when I compile the unit test executable, it has >> an error fatal error LNK1104: cannot open file >> 'libboost_regex-vc90-mt-gd-1_47.lib' If I add its directory C:\Program >> Files\boost\boost_1_47\lib to the linker's "Additional Library >> Directory" in VS2008 everything went OK. >> >> My question is >> >> 1. Where this "libboost*" comes from ? all my CMake script are giving >> boost_* instead of libboost_* libraries. >> 2. When to set this linker directory so I do not need to add this >> manually in VS2008. > > The libboost_* libraries are dragged in by auto-linking on Windows. > Auto-linking is ON by default on Windows. > You have to explicitly disable it. > > Go to CMake installation directory, locate FindBoost.cmake file, > open this file and read the comments where you have it explained very well. > > Best regards, > -- > Mateusz Loskot, http://mateusz.loskot.net Thanks for telling me the "auto-link" part. It works now. Actually I did look at the FindBoost.cmake, but did not get a direct answer for my case: Here is my working case: ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(example) ADD_SUBDIRECTORY(python) ADD_SUBDIRECTORY(test-suite) In ./src, I find boost components except the unit_test_framework. FIND_PACKAGE(Boost REQUIRED COMPONENTS regex program_options filesystem system) IF(Boost_FOUND) add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS}) MESSAGE(STATUS "Boost: ${Boost_LIBRARIES}") INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) ENDIF() in ./test-suite, It is: UNSET(Boost_LIBRARIES) SET(Boost_USE_STATIC_LIBS OFF) IF(UNIX) SET(Boost_USE_MULTITHREADED OFF) ENDIF(UNIX) find_package(Boost REQUIRED COMPONENTS unit_test_framework) INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS} ${GSL_INCLUDE_DIR}) # here is the unit-test executable TARGET_LINK_LIBRARIES(utest tesla-static glps-static ${Boost_LIBRARIES} hdf5_hl hdf5 ${Boost_REGEX_LIBRARY} ) SET_TARGET_PROPERTIES(utest PROPERTIES COMPILE_FLAGS "-DBOOST_TEST_DYN_LINK ${Boost_UNIT_TEST_FRAMEWORK_DYN_LINK}") IF(WIN32) SET_TARGET_PROPERTIES(utest PROPERTIES COMPILE_FLAGS "-DBOOST_ALL_NO_LIB -DBOOST_TEST_DYN_LINK ${Boost_UNIT_TEST_FRAMEWORK_DYN_LINK} ${Boost_LIB_DIAGNOSTIC_DEFINITIONS}") ENDIF(WIN32) Thanks. Forest -- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
