我有一个非常简单的提升应用程序:
#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
我的配置是不正确的?
谢谢!
答案 0 :(得分:4)
CMake区分大小写。使用find_package(Boost ...)
但不使用find_package(BOOST ...)
。
如果使用COMPONENTS
,则BTW REQUIRED
子选项是可选的:
find_package(Boost REQUIRED filesystem system)
答案 1 :(得分:0)
以下是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,虽然它没有在宏中特别提到。