[CMake] cmake, boost on windows, and linking: shouldn't find_package have put BOOST_ROOT/lib into LIB?
I'm slowly learning cmake and converting some real software to it, targeting Linux, Windows, and Mac OS X. Along the way, I'm making minimal working examples (they're a lot easier to debug them than the real thing) and putting them up at http://code.google.com/p/winezeug/source/browse/#svn/trunk/cmake_examples Today, I wrote an example that uses a single function from boost. It's at http://code.google.com/p/winezeug/source/browse/#svn%2Ftrunk%2Fcmake_examples%2Fex4 For Linux, demo.sh builds and runs the example, assuming you've installed everything needed with apt-get. For Windows (or Linux with Wine), demo.bat builds and runs the example, assuming you've installed visual c++ 2005 express, the win 7 platform sdk, and boostpro.com's pre-build boost (the whole thing, don't skip any libraries, or you may be mystified why things don't link, like I was).It sets BOOST_ROOT so find_package can find boost. And now the question. I needed to put $BOOST_ROOT/lib into the LIB environment variable by hand (well, by running http://code.google.com/p/winezeug/source/browse/trunk/cmake_examples/settings.bat ). If I leave it out, I get the error LINK : fatal error LNK1104: cannot open file 'libboost_date_time-vc80-mt-gd-1_47.lib' when bulding on Windows. Shouldn't find_package have taken care of that? -- 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
Re: [CMake] cmake, boost on windows, and linking: shouldn't find_package have put BOOST_ROOT/lib into LIB?
find_package() searches for a package, and sets variables. Typically variables like... _FOUND # package found or not _INCLUDE_DIR # path to the libraries include directory _LIBRARY # name of the library You still have to link in the library yourself: target_link_libraries(${TARGET} ${_LIBRARY}) For Boost, you can specify which libraries you are actually going to use: set(BOOST_ROOT path/to/Boost) # boost root dir find_package(Boost 1.47.0 COMPONENTS regex REQUIRED) # find the regex lib ... include_directories(${Boost_INCLUDE_DIR}) # if you use Boost header only, this is all you need … target_link_libraries(${TARGET} ${Boost_REGEX_LIBRARY}) # link in the regex lib from boost. Daniel On Oct 29, 2011, at 4:11 AM, Dan Kegel wrote: > I'm slowly learning cmake and converting some real software to it, > targeting Linux, Windows, and Mac OS X. > Along the way, I'm making minimal working examples (they're a lot > easier to debug them than the real thing) and putting them up at > http://code.google.com/p/winezeug/source/browse/#svn/trunk/cmake_examples > > Today, I wrote an example that uses a single function from boost. It's at > > http://code.google.com/p/winezeug/source/browse/#svn%2Ftrunk%2Fcmake_examples%2Fex4 > > For Linux, demo.sh builds and runs the example, assuming you've > installed everything needed with apt-get. > For Windows (or Linux with Wine), demo.bat builds and runs the > example, assuming you've installed visual c++ 2005 express, the win 7 > platform sdk, and boostpro.com's pre-build boost (the whole thing, > don't skip any libraries, or you may be mystified why things don't > link, like I was).It sets BOOST_ROOT so find_package can find > boost. > > And now the question. > I needed to put $BOOST_ROOT/lib into the LIB environment variable by > hand (well, by running > http://code.google.com/p/winezeug/source/browse/trunk/cmake_examples/settings.bat > ). > If I leave it out, I get the error > LINK : fatal error LNK1104: cannot open file > 'libboost_date_time-vc80-mt-gd-1_47.lib' > when bulding on Windows. > Shouldn't find_package have taken care of that? > -- > > 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 -- 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
Re: [CMake] cmake, boost on windows, and linking: shouldn't find_package have put BOOST_ROOT/lib into LIB?
On Sun, Oct 30, 2011 at 5:46 AM, Daniel Dekkers wrote: > find_package() searches for a package, and sets variables. Typically > variables like... > > _FOUND # package found or not > _INCLUDE_DIR # path to the libraries include directory > _LIBRARY # name of the library > > You still have to link in the library yourself: > > target_link_libraries(${TARGET} ${_LIBRARY}) > > For Boost, you can specify which libraries you are actually going to use: > > set(BOOST_ROOT path/to/Boost) # boost root dir > find_package(Boost 1.47.0 COMPONENTS regex REQUIRED) # find the regex lib > > ... > > include_directories(${Boost_INCLUDE_DIR}) # if you use Boost header only, > this is all you need > > … > > target_link_libraries(${TARGET} ${Boost_REGEX_LIBRARY}) # link in the regex > lib from boost. > > Daniel > > On Oct 29, 2011, at 4:11 AM, Dan Kegel wrote: > >> I'm slowly learning cmake and converting some real software to it, >> targeting Linux, Windows, and Mac OS X. >> Along the way, I'm making minimal working examples (they're a lot >> easier to debug them than the real thing) and putting them up at >> http://code.google.com/p/winezeug/source/browse/#svn/trunk/cmake_examples >> >> Today, I wrote an example that uses a single function from boost. It's at >> http://code.google.com/p/winezeug/source/browse/#svn%2Ftrunk%2Fcmake_examples%2Fex4 >> >> For Linux, demo.sh builds and runs the example, assuming you've >> installed everything needed with apt-get. >> For Windows (or Linux with Wine), demo.bat builds and runs the >> example, assuming you've installed visual c++ 2005 express, the win 7 >> platform sdk, and boostpro.com's pre-build boost (the whole thing, >> don't skip any libraries, or you may be mystified why things don't >> link, like I was). It sets BOOST_ROOT so find_package can find >> boost. >> >> And now the question. >> I needed to put $BOOST_ROOT/lib into the LIB environment variable by >> hand (well, by running >> http://code.google.com/p/winezeug/source/browse/trunk/cmake_examples/settings.bat >> ). >> If I leave it out, I get the error >> LINK : fatal error LNK1104: cannot open file >> 'libboost_date_time-vc80-mt-gd-1_47.lib' >> when bulding on Windows. >> Shouldn't find_package have taken care of that? >> -- >> >> 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 > > -- > > 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 > The typical target_link_libraries call should name the libraries by full path, and avoid requiring anything with respect to environment variables. Environment variable values may be used as hints or pointers about where to find something, but CMake does not modify your environment or set up any environment in the generated makefiles. If a project has requirements about the environment in which it runs, it is expected that the project's CMakeLists files will document/enforce such requirements. HTH, David -- 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
Re: [CMake] cmake, boost on windows, and linking: shouldn't find_package have put BOOST_ROOT/lib into LIB?
Thanks to David & Daniel for the replies, but I was already doing everything by the book, so their replies didn't help. It seems to be a bug, or flaky feature, in boost; I had to disable "auto-linking". Here's the final, working CMakeLists.txt: cmake_minimum_required(VERSION 2.8) # Turn off boost's autolinking feature, since it seems to guess wrong about the name of the library add_definitions(-DBOOST_ALL_NO_LIB) find_package(Boost 1.45 COMPONENTS date_time REQUIRED) include_directories(${Boost_INCLUDE_DIRS}) add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS}) add_executable(mymain mymain.cpp) target_link_libraries(mymain ${Boost_LIBRARIES}) The only change from before was adding the add_definitions line. -- 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