[CMake] Linking with MSVC against Boost lib fails to find library

Doug Gregor doug.gregor at gmail.com
Fri Jul 11 09:29:57 EDT 2008


On Fri, Jul 11, 2008 at 7:33 AM, Stephen Collyer
<scollyer at netspinner.co.uk> wrote:
> I'm getting a link failure under Visual Studio with Boost.
> The installed Boost library in question is:
>
> boost_program_options-vc80-mt-gd-1_34_1.lib
>
> In my CMakeLists.txt file, I refer to this lib via
>
> ${BOOST_PROGRAM_OPTIONS_LIBRARY}
>
> However, the link fails with a message telling me that VS
> can't find:
>
> libboost_program_options-vc80-mt-gd-1_34_1.lib
>
> i.e. with a leading "lib".
>
> The link command generated by VS does *not* have this leading
> "lib" and refers to the correct library name so I'm confused as
> to why VS is looking for the incorrect library, when it actually
> performs the link.
>
> Can anyone suggest what I'm doing wrong ?

So, it looks like Boost's auto-linking is trying to link against the
static program_options library (with the lib prefix), but CMake has
found the shared program_options library. You'll need to force it one
way or the other.

If you want to force CMake to find the static versions, use

  SET(Boost_USE_STATIC_LIBS ON)

before using find_package(Boost).

To force your program to link against the shared version of the Boost
libraries, use

  add_definitions(-DBOOST_ALL_DYN_LINK)

  - Doug

> --
> Regards
>
> Steve Collyer
> Netspinner Ltd
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list