[CMake] cmake, boost on windows, and linking: shouldn't find_package have put BOOST_ROOT/lib into LIB?

David Cole david.cole at kitware.com
Sun Oct 30 10:44:06 EDT 2011


On Sun, Oct 30, 2011 at 5:46 AM, Daniel Dekkers <d.dekkers at cthrough.nl> wrote:
> find_package() searches for a package, and sets variables. Typically variables like...
>
> <package>_FOUND # package found or not
> <package>_INCLUDE_DIR # path to the libraries include directory
> <package>_LIBRARY # name of the library
>
> You still have to link in the library yourself:
>
> target_link_libraries(${TARGET} ${<package>_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


More information about the CMake mailing list