【发布时间】: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();
}
谢谢!
【问题讨论】:
-
@roalz 我不这么认为。 CMake“认为”它已经成功添加了 boost,但它没有将它们包含在生成的项目中,
-
@user2448431 看到我对我的回答的补充,你缺少 target_include_directories()。如果它适合您,请接受它作为答案。
标签: c++ visual-studio boost cmake