Find_package from cmake cannot find boost

I referenced this link and made a CMakeLists.txt with the 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 if I set BOOST_ROOT it fails and gives Boost Found False message . What am I doing wrong here?

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

+3


source to share


2 answers


I found the reason why this code doesn't work. Since I am giving the ON value for 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 . See Fig. Below: Boost default linking



0


source


Your directory structure should look like this:

c:/boost/boost_1_55_0

      



and BOOST_ROOT is the environment variable set in c: / boost

0


source







All Articles