如何在linux中使用boost

时间:2022-12-04 00:16:38

I'm trying to use the shared pointer class(?) from boost. I have downloded boost and extracted it to a subfolder(boost) in my source folder (src). I have then added a line:

我正在尝试使用boost中的共享指针类(?)。我已经下载了boost并将其解压缩到我的源文件夹(src)中的子文件夹(boost)。然后我添加了一行:

#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机器

3 个解决方案

#1


11  

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

您将需要使用g ++将目录添加为编译选项,如g ++ -I./boost ...或基本上添加为命令行选项-I直接跟随没有空格的相对或绝对路径已安装你的升级库。还要记住,为了将来的参考,boost的一些元素,比如线程库也需要链接一些库,并且你必须在编译时使用-L选项包含那些文件路径...这不是使用boost :: shared_ptr的情况,但只是让你头脑发热。

#2


5  

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)

#3


2  

You can add gcc -I option. Documentation.

您可以添加gcc -I选项。文档。

#1


11  

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

您将需要使用g ++将目录添加为编译选项,如g ++ -I./boost ...或基本上添加为命令行选项-I直接跟随没有空格的相对或绝对路径已安装你的升级库。还要记住,为了将来的参考,boost的一些元素,比如线程库也需要链接一些库,并且你必须在编译时使用-L选项包含那些文件路径...这不是使用boost :: shared_ptr的情况,但只是让你头脑发热。

#2


5  

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)

#3


2  

You can add gcc -I option. Documentation.

您可以添加gcc -I选项。文档。