C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了c – 为什么这个boost头文件不包括在内大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在Mac上用cmake构建我的c程序.编译器给我以错误
error: boost/filesystem.hpp: No such file or directory

触发错误的行如下:

#include "boost/filesystem.hpp"

要么

#include <boost/filesystem.hpp>

我使用以上哪项不会改变错误

但是在我的CMakeLists.txt中,我将以下列方式包含boost头:

FIND_PACKAGE(Boost) 
messaGE("Boost information:") 
messaGE("  Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}") 
messaGE("  Boost_LIBRARIES: ${Boost_LIBRARIES}") 
messaGE("  Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}") 

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})

在cmake过程中,Boost包含dirs已填充“/ opt / local / include /”,此文件夹包含一个包含filesystem.hpp的文件夹boost

Boost在@L_188_10@makefile时给出以下消息,我只复制boost部分:

-- Boost version: 1.38.0
-- Found the following Boost libraries:
Boost information:
Boost_INCLUDE_DIRS: /opt/local/include
Boost_LIBRARIES: 
Boost_LIBRARY_DIRS: /opt/local/lib
-- Configuring done

当运行make VERBOSE = 1此行包含错误

cd /Users/janusz/Documents/workspace/ImageMarker/Debug/src && 
/usr/bin/c++ -O3 -Wall -Wno-deprecated -g -verbose -I/Users/janusz/Documents/workspace/ImageMarker/src/. -o CMakeFiles/ImageMarker.dir/FaceRecognizer.cpp.o -c /Users/janusz/Documents/workspace/ImageMarker/src/FaceRecognizer.cpp
/Users/janusz/Documents/workspace/ImageMarker/src/FaceRecognizer.cpp:8:32: error: boost/filesystem.hpp: No such file or directory
make[2]: *** [src/CMakeFiles/ImageMarker.dir/FaceRecognizer.cpp.o] Error 1

你明白为什么编译器没有选择/ opt / local / include目录?

如果您需要更多信息,我很乐意提供

解决方法

首先使用
FIND_PACKAGE(Boost required)

而不是

FIND_PACKAGE(Boost)

这样,在开始任何编译之前,如果没有找到它,cmake会给你一个很好的错误消息.如果没有将环境变量BOOST_ROOT设置为/ opt / local(这是安装前缀).
此外,您将不得不链接文件系统库,所以你想要

FIND_PACKAGE(Boost COMPONENTS filesystem required)

供以后使用

target_link_libraries(myTarget ${Boost_FILESYstem_LIBRARY})

输入

cmake --Help-module FindBoost

在sHell中获取cmake安装中的Boost查找模块的文档.

PS:一个例子

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
project(Foo)

find_package(Boost COMPONENTS filesystem required)

include_directories(${Boost_INCLUDE_DIRS})
add_executable(foo main.cpp)
target_link_libraries(foo 
  ${Boost_FILESYstem_LIBRARY}
)
@H_878_4@main.cpp中

#include <boost/filesystem.hpp>
#include <vector>
#include <String>
#include <cstdio>
#include <cstddef>

namespace fs = boost::filesystem;
using namespace std;

int main(int argc,char** argv)
{
  vector<String> args(argv+1,argv+argc);
  if(args.empty())
  {
    printf("usage: ./foo SOME_PATH\n");
    return EXIT_FAILURE;
  }

  fs::path path(args.front());

  if(fs::exists(path))
    printf("%s exists\n",path.String().c_str());
  else
    printf("%s doesn't exist\n",path.String().c_str());

  return EXIT_succesS;
}

大佬总结

以上是大佬教程为你收集整理的c – 为什么这个boost头文件不包括在内全部内容,希望文章能够帮你解决c – 为什么这个boost头文件不包括在内所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。