这是为什么升压头文件中不包括 [英] Why is this boost header file not included

查看:157
本文介绍了这是为什么升压头文件中不包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立我的C ++程序与Mac上的CMake。编译器给了我以下错误:

I'm building my c++ program with cmake on a Mac. The compiler gives me following Error:

error: boost/filesystem.hpp: No such file or directory

这触发错误的行是:

#include "boost/filesystem.hpp"

#include <boost/filesystem.hpp>

这上面我用不改变错误

Which of the above I use doesn't changed the Error

但是,在我的CMakeLists.txt我包括以下列方式升压标头:

But in my CMakeLists.txt I include the boost headers in the following way:

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})

升压include目录充满了/选择/本地/包括/在cmake的过程,并在此文件夹中包含其中包含filesystem.hpp文件夹提振

Boost include dirs is filled with "/opt/local/include/" during the cmake process and this folder contains a folder boost which contains the filesystem.hpp

加速提供了以下信息,同时生成的Makefile,我只复制了部分提振:

Boost gives the following messages while generating the Makefile, I only copied the boost part:

-- 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

在运行使VERBOSE = 1这一行包含错误:

While running make VERBOSE=1 This line contains the error:


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 /本地/ include目录?

Do you understand why the compiler isn't picking the /opt/local/include directory?

如果您需要更多的信息,我很高兴向它提供

If you need more information I'm happy to provide it

推荐答案

全部使用首先

FIND_PACKAGE(Boost REQUIRED)

而不是

  FIND_PACKAGE(Boost)

这样的CMake会给你一个不错的错误信息,如果任何编译启动之前没有找到它,很长。如果失败设置环境变量BOOST_ROOT到/ opt /本地(即安装preFIX)。
此外,您将在文件系统库进行链接,让您随心所欲

This way cmake will give you a nice error message if it doesn't find it, long before any compilations are started. If it fails set the environment variable BOOST_ROOT to /opt/local (which is the install prefix). Additionally you will have to link in the filesystem library, so you want

FIND_PACKAGE(Boost COMPONENTS filesystem REQUIRED)

以备后用

target_link_libraries(mytarget ${Boost_FILESYSTEM_LIBRARY})

输入

cmake --help-module FindBoost

在shell得到了提振文档找到你的CMake安装模块。

at the shell to get the docs for the Boost find module in your cmake installation.

PS:一个例子

本的CMakeLists.txt

The 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}
)

的main.cpp

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;
}

这篇关于这是为什么升压头文件中不包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆