簡體   English   中英

在CMake中正確配置Boost

[英]Properly configuring boost in CMake

我有一個非常簡單的增強應用程序:

#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_LIBRARIESBoost_LIBRARIES有我需要的嗎? 在上面的配置中,它是一個瑣碎的空字符串。 我正在使用OSX / Homebrew中的 {cmake,boost1.5}

我的配置不正確嗎?

謝謝!

CMake區分大小寫。 使用find_package(Boost ...)而不要使用find_package(BOOST ...) BTW COMPONENTS ,如果子選項是可選的REQUIRED使用:

find_package(Boost REQUIRED filesystem system)

以下是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,盡管在宏中沒有特別提及。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM