Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
671 views
in Technique[技术] by (71.8m points)

windows - CMake doesn't find Boost libraries

I'm trying to use a CMake script to compile a Boost-based application on Windows. The header-only libraries work fine, but CMake fails to find the libraries (the following Boost libraries could not be found: boost_serialization). The relevant part of the CMake script is:

# Path where CMake can find additional libraries
SET(CMAKE_PREFIX_PATH Libs)

# Boost
SET(Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0")
SET(Boost_USE_STATIC_LIBS   ON)
find_package(Boost REQUIRED COMPONENTS serialization)

I have a folder called "Libs" inside my project where third-party libraries such as DevIL and Boost are stored, so I set this first. It works fine for Devil and Boost header-only stuff, so I assume I should not need the BOOST_ROOT variable. The Boost installation is the standard source distribution from boost.org which I compiled with BJam. The libraries are stored in boost_1_47_0in.v2libs, and I didn't change anything in the build process.

I think it is a bit odd, that the boost_1_47_0libs folder doesn't contain any library files but BJam files and other stuff, but that shouldn't be a problem since this seems to be the normal way to build Boost on Windows from the source.

I looked at the Debug output from the FindBoost.cmake file (I'm using the default script from CMake 2.8) and it doesn't seem to look into bin.v2. Instead it searches boost_ROOT/lib, but when I copied the content from bin.v2libs to lib it still didn't find anything.

So what is an elegant way to find Boost that will also work on other platforms with common Boost distributions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would try setting BOOST_ROOT inside your CMakeLists.txt file. I know that CMake 2.8.6 will find Boost 1.47.0 when you set the Boost_ADDITIONAL_VERSIONS variable since it works for me on Windows when I have BOOST_ROOT set.

Here is what I have in one project:


    set( BOOST_COMPONENTS_NEEDED serialization )

    # The following verifyies that BOOST_ROOT is set properly.
    if(NOT BOOST_ROOT AND NOT $ENV{BOOST_ROOT} STREQUAL "")
        FILE( TO_CMAKE_PATH $ENV{BOOST_ROOT} BOOST_ROOT )
        if( NOT EXISTS ${BOOST_ROOT} )
            MESSAGE( STATUS  ${BOOST_ROOT} " does not exist. Checking if BOOST_ROOT was a quoted string.." )
            STRING( REPLACE """ "" BOOST_ROOT ${BOOST_ROOT} )
            if( EXISTS ${BOOST_ROOT} )
                MESSAGE( STATUS "After removing the quotes " ${BOOST_ROOT} " was now found by CMake" )
            endif( EXISTS ${BOOST_ROOT})
        endif( NOT EXISTS ${BOOST_ROOT} )

    # Save the BOOST_ROOT in the cache
        if( NOT EXISTS ${BOOST_ROOT} )
            MESSAGE( WARNING ${BOOST_ROOT} " does not exist." )
        else(NOT EXISTS ${BOOST_ROOT})
            SET (BOOST_ROOT ${BOOST_ROOT} CACHE STRING "Set the value of BOOST_ROOT to point to the root folder of your boost install." FORCE)
            #SET (BOOST_INCLUDEDIR ${BOOST_ROOT}/Include)
            #SET (BOOST_LIBRARYDIR ${BOOST_ROOT}/lib)
        endif( NOT EXISTS ${BOOST_ROOT} )

    endif(NOT BOOST_ROOT AND NOT $ENV{BOOST_ROOT} STREQUAL "")

    if( WIN32 AND NOT BOOST_ROOT )
        MESSAGE( WARNING "Please set the BOOST_ROOT environment variable." )
    endif( WIN32 AND NOT BOOST_ROOT )

    set(Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0")
    set(Boost_DEBUG ON)
    set(Boost_USE_STATIC_LIBS       OFF)
    set(Boost_USE_MULTITHREADED      ON)
    set(Boost_USE_STATIC_RUNTIME    OFF)
    FIND_PACKAGE(Boost 1.47.0 COMPONENTS ${BOOST_COMPONENTS_NEEDED})
    if(Boost_FOUND)
        MESSAGE( STATUS "Setting up boost." )
        include_directories(${Boost_INCLUDE_DIRS})
        if(Boost_DEBUG)
            MESSAGE( STATUS "BOOST Libraries " ${Boost_LIBRARIES} )
            FOREACH(BOOST_COMPONENT ${BOOST_COMPONENTS_NEEDED})
                STRING( TOUPPER ${BOOST_COMPONENT} BOOST_COMPONENT_UPCASE )
                MESSAGE( STATUS "Boost " ${BOOST_COMPONENT} ": " ${Boost_${BOOST_COMPONENT_UPCASE}_LIBRARY} )
                MESSAGE( STATUS "Boost " ${BOOST_COMPONENT} " Debug: " ${Boost_${BOOST_COMPONENT_UPCASE}_LIBRARY_DEBUG} )
                MESSAGE( STATUS "Boost " ${BOOST_COMPONENT} " Release: " ${Boost_${BOOST_COMPONENT_UPCASE}_LIBRARY_RELEASE} )
            ENDFOREACH(BOOST_COMPONENT)
        endif(Boost_DEBUG)
    endif(Boost_FOUND)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...