CMake没有将boost目录包含在它生成的项目中

时间:2017-02-02 15:03:23

标签: c++ visual-studio boost cmake

我一直在尝试创建一个CMake项目,然后使用Visual Studio 2015进行编译。但是,当我生成项目文件时,不包括boost。以下是CMake生成的相关输出:

  

Boost版本:1.62.0
  找到以下Boost库:
  系统
  线程
  计时
  DATE_TIME
  原子
  配置完成
  生成完成

路径都是正确的。 CMake应该将include目录放到VC ++目录中? 构建系统哪里出错?

实际的CMakeLists.txt如下:

#MultiTracker Application
cmake_minimum_required (VERSION 3.1)
project(MultiTracker)

#Additional CMake search modules

#Require C++11
set (CMAKE_CXX_STANDARD 11)
message(STATUS "Generating Makefile for MultiTracker")

file(GLOB SRC_FILES *.cpp)
#Find and link boost
SET(Boost_USE_STATIC_LIBS   ON)
find_package(Boost REQUIRED system thread)

add_executable(MultiTracker ${SRC_FILES})
#Link internal libraries

#Link 3rd party libraries
target_link_libraries(MultiTracker ${Boost_LIBRARIES})

#The native OS thread library
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(MultiTracker Threads::Threads)

Main.cpp的

//System Includes
#include <iostream>
#include <cstdlib>    

//Library Includes
#include <boost/program_options.hpp>
#include <boost/format.hpp>

//Local Includes    


int main(int iArgc, char *cpArgv[])
{
    std::string confName = "Conf.json", outFileName, inFileName;

    //setup the program options
    boost::program_options::options_description oPODescriptions("Available options");
    oPODescriptions.add_options()
        ("help", "help message")
        ("confFile", boost::program_options::value<std::string>(&confName)->default_value("pclConf.json"), "Name of the configuration file to use");

    boost::program_options::variables_map mapVars;
    try
    {
        boost::program_options::store(boost::program_options::parse_command_line(iArgc, cpArgv, oPODescriptions), mapVars);
        boost::program_options::notify(mapVars);
    }
    catch (std::exception &e)
    {
        std::cerr << e.what() << std::endl;
        return 2;
    }

    //print the help message
    if (mapVars.count("help"))
    {
        std::cout << "Stack Overflow Test: " << oPODescriptions << std::endl;
        return ~0;
    }

    std::cout << "Press enter to exit" << std::endl;
    std::cin.get();
}

谢谢!

1 个答案:

答案 0 :(得分:4)

您还应该在您的问题中包含您如何在CMakeLists.txt文件中管理Boost依赖项。

如果您使用了find_package(Boost)(see reference here),则 您应该将Boost_INCLUDE_DIRS添加到目标项目包含目录, 和Boost_LIBRARIES到项目链接的库。

在此处查看非常相似的问题和答案:How do you add boost libraries in CMakeLists.txt

问题编辑后添加
你错过了:

target_include_directories(MultiTracker PRIVATE ${Boost_INCLUDE_DIRS})

(在您的情况下不确定“私人”)