我已提到此link并使用以下数据制作了CMakeLists.txt:
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()
即使我设置了 BOOST_ROOT ,它也会失败并显示 Boost Found False 消息。我在这做错了什么?
修改:我发现将 Boost_USE_STATIC_LIBS 设置为关闭正在解决此问题。但我必须 ON 。这可能有什么问题?
答案 0 :(得分:0)
您的目录结构必须如下所示:
c:/boost/boost_1_55_0
和BOOST_ROOT是一个设置为c:/ boost
的环境变量答案 1 :(得分:0)
我找到了此代码无效的原因。当我将值 ON 赋予 Boost_USE_STATIC_LIBS 时,结果是 find_package 会查找 libboost_thread-vc100-mt- 1_55 ,它找不到,因为构建提升将提供此link中所述的共享库。请参考下面的图片: