正确配置CMake中的boost
Properly configuring boost in CMake
我有一个非常简单的boost应用程序:
#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})
注意上面文件中的USE_BOOST_LIB_HACK
。但是Boost_LIBRARIES
不应该有我需要的吗?在上面的配置中,它是一个普通的空字符串。我使用{cmake,boost1.5}从OSX/Homebrew
我的配置是否不正确?
谢谢!
CMake区分大小写。使用find_package(Boost ...)
,不使用find_package(BOOST ...)
。BTW COMPONENTS
子选项是可选的,如果REQUIRED
使用:
find_package(Boost REQUIRED filesystem system)
- 可能解释:http://pastebin.com/qQyGnQDL
以下是FindBoost.cmake
的文档如何描述宏的正确使用:
#
# set(Boost_USE_STATIC_LIBS ON)
# set(Boost_USE_MULTITHREADED ON)
# set(Boost_USE_STATIC_RUNTIME OFF)
# find_package( Boost 1.36.0 COMPONENTS date_time filesystem system ... )
#
# if(Boost_FOUND)
# include_directories(${Boost_INCLUDE_DIRS})
# add_executable(foo foo.cc)
# target_link_libraries(foo ${Boost_LIBRARIES})
# endif()
这个方法在Linux上确实工作得很好。但我不确定MacOSX/HomeBrew,尽管它没有在宏中特别提到。
相关文章:
- 相当于 pybind11 中的 boost::p ython py::scope().attr()
- 告诉CMake链接到自定义文件夹中的Boost
- 如何正确取消析构函数中的 Boost deadline_timer(在多线程环境中)?
- 非推导上下文,如标准库中的"boost::mpl::identity:<T>:type"?
- C 11中的Boost ::变体和多态性
- TCP中的Boost async处理程序
- 在Windows 10中的Boost :: FileSystem :: remove_all遇到问题
- 在C 中的Boost库中可辍学的蓄能器的优势是什么?
- Eclipse中的Boost TestRunner无法生成有效的XML
- 使用C 中的Boost中的GIL将图像定位在图像中
- Cygwin目录迭代器中的Boost文件系统
- 使用访问者中的Boost变体中的类型不编译
- CPP中的BOOST.ASIO SERVER-CLIENT程序
- 默认模板函数参数中的 boost::shared_ptr 和 nullptr
- 链接ubuntu 14.04中的boost文件系统和boost iostream库
- 链接XCode中的Boost库
- 使用MPI中的Boost发送链接列表
- 如何仅在使用 c++ 中的 boost 完成所有任务时才向线程池添加新任务
- 链接CodeBlocks中的Boost库(使用MinGW)
- 用C++中的BOOST序列化循环图