简体   繁体   English

如何在linux中使用boost

[英]how to use boost in linux

I'm trying to use the shared pointer class(?) from boost. 我正在尝试使用boost中的共享指针类(?)。 I have downloded boost and extracted it to a subfolder(boost) in my source folder (src). 我已经下载了boost并将其解压缩到源文件夹(src)中的子文件夹(boost)。 I have then added a line: 然后我添加了一行:

#include "boost/shared_ptr.hpp"

When I try to compile, I get an error: 当我尝试编译时,我收到一个错误:

error: boost/smart_ptr/shared_ptr.hpp: No such file or directory 错误:boost / smart_ptr / shared_ptr.hpp:没有这样的文件或目录

What do I have to add for the program to compile? 我需要为程序编译添加什么?

I'm working on a scientific linux machine without root privliges 我正在研究一台没有root权限的科学linux机器

You will need to, with g++ , add the directory as a compile option like g++ -I./boost ... or basically add as a command line option -I directly followed without a space by the relative or absolute path where you have installed your boost library. 您将需要使用g++将目录添加为编译选项,如g++ -I./boost ...或基本上添加为命令行选项-I直接跟随没有空格的安装的相对或绝对路径你的助推库。 Keep in mind also for future reference that some elements of boost, like the threading library also require some libraries to be linked against, and you will have to also include those file-paths at compile time using the -L option ... that isn't the case with boost::shared_ptr , but just giving you a head's up. 请记住,以便将来参考boost的某些元素,比如线程库也需要链接一些库,并且你必须在编译时使用-L选项包含那些文件路径...这不是使用boost::shared_ptr的情况,但只是让你boost::shared_ptr

Assuming you have installed boost to some subdirectory of your home directory, you'll need to do one of these to specify where the compiler should look for the boost header files: 假设您已经在主目录的某个子目录中安装了boost,那么您需要执行以下操作之一来指定编译器应该查找boost头文件的位置:

  • add a -I flag to the compiler command line ( GCC docs ) 在编译器命令行中添加-I标志( GCC docs
  • set the CPLUS_INCLUDE_PATH environment variable ( GCC docs ) 设置CPLUS_INCLUDE_PATH环境变量( GCC docs

You can add gcc -I option. 您可以添加gcc -I选项。 Documentation . 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM