简体   繁体   中英

find_package of cmake cannot find boost

I have referred to this link and made a CMakeLists.txt with following data:

cmake_minimum_required(VERSION 2.8)
SET(TARGET integrity_scanner)
message("\nBuilding ${TARGET}")
project (${TARGET})
if (UNIX)
    message(STATUS "Setting GCC flags")
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -Wall -O0")
else()
    message(STATUS "Setting MSVC flags")
    #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHc-")
endif ()

include_directories ("${PROJECT_SOURCE_DIR}")

set(Boost_USE_STATIC_LIBS       ON)
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)
set(BOOST_ROOT C:/boost_1_55_0_dyn)
find_package(Boost 1.55.0 COMPONENTS thread)

SET(SOURCE
  IntegrityScanner.cpp
)

SET(HEADERS
  IntegrityScanner.h ../BaseApplication.hpp 
)

if(Boost_FOUND)
    add_definitions(-DDLL_EXPORTS)
    add_definitions(-DBOOST_ALL_DYN_LINK)

    include_directories("..\\..\\..\\ext_library\\zmq\\zeromq-4.0.3\\include")
    include_directories("..\\..\\..\\ext_library\\zmq\\czmq\\czmq-2.1.0\\include")
    link_directories("..\\..\\..\\ext_library\\zmq\\zeromq-4.0.3\\lib\\Win32\\Debug")
    link_directories("..\\..\\..\\ext_library\\zmq\\czmq\\czmq-2.1.0\\lib\\Win32\\DebugDLL")

    include_directories(${Boost_INCLUDE_DIRS}) 
    LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
    add_library(${TARGET} SHARED ${SOURCE} ${HEADERS})
    target_link_libraries(${TARGET} ${Boost_LIBRARIES} czmq libzmq)
else()
    message(STATUS "Boost_FOUND False")
endif()

Even though I have set BOOST_ROOT , it fails and gives the Boost Found False Message. What am I doing wrong here?

Edit: I have found that setting Boost_USE_STATIC_LIBS to OFF is resolving the issue. But I have to have it ON . What could be wrong here?

Your directory structure needs to look like this:

c:/boost/boost_1_55_0

and BOOST_ROOT is an environment variable set to c:/boost

I have found the reason why this code is not working. As I am giving value ON to Boost_USE_STATIC_LIBS , the result is that find_package will look for libboost_thread-vc100-mt-1_55 , which it will not find because building boost will give shared libraries as stated in this link . Refer to pic below: 提升默认链接

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM