我有一个非常简单的增强应用程序:
#include <iostream>
#include "boost/filesystem.hpp"
int main(int /*argc*/, char** /*argv*/) {
if( boost::filesystem::exists(".") )
std::cout << "exists" << std::endl;
return 0;
}
我用CMake配置的:
cmake_minimum_required (VERSION 2.8 FATAL_ERROR)
set(USE_BOOST_LIB_HACK TRUE)
#--- Boost (TODO: wrong libraries linked)
find_package (BOOST COMPONENTS filesystem system REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
if(USE_BOOST_LIB_HACK)
#--- Now I need to manually append them to avoid missing symbols
list(APPEND libs /usr/local/lib/libboost_system.dylib)
list(APPEND libs /usr/local/lib/libboost_filesystem.dylib)
else()
list(APPEND libs ${Boost_LIBRARIES})
message(STATUS BOOST: ${Boost_LIBRARIES}) #<<< EMPTY :( :(
endif()
#--- Add all sources in this folder
file(GLOB_RECURSE hdrs "*.h")
file(GLOB_RECURSE srcs "*.cpp")
#--- Create executable and link
set(CMAKE_BUILD_TYPE "Debug")
add_executable(boost ${hdrs} ${srcs})
target_link_libraries(boost ${libs})
注意上面文件中的hack
USE_BOOST_LIB_HACK
。但是Boost_LIBRARIES
不应该有我需要的吗?在上面的配置中,它是一个琐碎的空字符串。我正在使用OSX / Homebrew中的{cmake,boost1.5}我的配置不正确吗?
谢谢!
最佳答案
CMake区分大小写。使用find_package(Boost ...)
,但不能使用find_package(BOOST ...)
。
如果使用了COMPONENTS
,则BTW REQUIRED
子选项是可选的:
find_package(Boost REQUIRED filesystem system)
可能的解释:http://pastebin.com/qQyGnQDL
关于c++ - 在CMake中正确配置Boost,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23782799/