【问题标题】:CMake is not including boost directories into it's generated projectsCMake 不将 boost 目录包含在其生成的项目中
【发布时间】:2017-06-19 17:21:52
【问题描述】:

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

增强版本:1.62.0
找到以下 Boost 库:
系统
线程
计时
日期时间
原子
配置完成
生成完成

而且路径都是正确的。 CMake 应该将包含目录放在 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();
}

谢谢!

【问题讨论】:

标签: c++ visual-studio boost cmake


【解决方案1】:

您还应该在问题中包括您是如何在 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})

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-29
    • 2022-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多