Couldn't find boost folders in '/usr/include' and '/usr/local/include' when installed using "sudo dnf -y install boost"

huangapple go评论66阅读模式
英文:

Couldn't find boost folders in '/usr/include' and '/usr/local/include' when installed using "sudo dnf -y install boost"

问题

我对CPP中的附加库相对陌生,并且正在使用CentOS 8.5.2111GCC 8.5.0 20210514开发服务器。我尝试安装Boost库以使用Boost图形,使用以下命令 -

sudo dnf makecache --refresh
sudo dnf -y install boost

我编写了一个非常基本的CPP程序来导入Boost图形库 -

#include <iostream>
#include <boost/graph/adjacency_list.hpp>

using namespace std;

int main(){
    cout << "Hello World!";
    return 0;
}

然后使用以下命令编译程序 -

g++ network_task.cpp -o network

但是遇到了以下错误 -

network_task.cpp:2:9: fatal error: boost/graph/adjacency_list.hpp: No such file or directory
 #include <boost/graph/adjacency_list.hpp>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

我查看了其他答案,它们建议包括Boost文件夹的完整路径。首先,我尝试在编译时添加Boost作为参数 -

g++ -I /usr/include/boost network_task.cpp -o network

但是仍然遇到相同的错误。

然后,我尝试查找Boost文件夹,唯一的路径我能找到的是/usr/share/licenses/boost-graph,其中只包含LICENSE_1_0.txt,在/usr/include/usr/local/include中没有任何内容。

请问是否有其他安装Boost图形库的方法,或者是否有其他包含所需文件的文件夹?还请帮助我如何包含Boost图形头文件并编译程序。

英文:

I am fairly new to Additional Libraries in CPP and was working on a server with CentOS 8.5.2111 with GCC 8.5.0 20210514. I tried installing Boost Library to use Boost Graphs using the following commands -
sudo dnf makecache --refresh
sudo dnf -y install boost

I wrote a very basic CPP program to import the boost graph libraries -

#include&lt;iostream&gt;
#include&lt;boost/graph/adjacency_list.hpp&gt;

using namespace std;

int main(){
    cout&lt;&lt;&quot;Hello World!&quot;;
    return 0;
}

and compiled the program using the following command -
gcc network_task.cpp -o network
but was met with the following error -

network_task.cpp:2:9: fatal error: boost/graph/adjacency_list.hpp: No such file or directory
 #include&lt;boost/graph/adjacency_list.hpp&gt;
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

I looked at other answers and they said to include the complete path of boost folder. First, I tried adding the boost as an argument while compiling -
gcc -I boost network_task.cpp -o network
but was met with the same error.

Then, I tried finding the folder for boost and the only path I could find was /usr/share/licenses/boost-graph which contained only the LICENSE_1_0.txt and nothing was present in the /usr/include and /usr/local/include.

Is there any other way I should install the boost library for graphs or is there any other folder where the required files are present? Also, help me with how to include the boost header file for the graphs and compile the program.

答案1

得分: 1

问题已经解决。
原来,除了 boost,我还需要安装 boost-devel。但由于 sudo 命令不在我的权限范围内,我无法控制安装哪些软件包以及哪些不安装。

sudo dnf -y install boost-devel 解决了问题。

感谢 @Homer512 的建议 -

大多数 Linux 发行版将其库拆分为一个二进制包(位于 /lib/bin 中的所有内容)和一个开发者包,其中包含头文件和其他编译自己代码所需的东西。看看是否有一个名为 boost-devel 或类似的软件包

另外,要编译程序,g++ network_task.cpp -o network 简单有效。

英文:

The problem has been solved.
Turns out, along with boost, I also had to install boost-devel. But, since the sudo commands were not under my priviledge, I had no control on what packages to install and what not.

sudo dnf -y install boost-devel did the trick.

Thanks @Homer512 for the advice -
> Most linux distributions split their libraries into a binary package (everything in /lib and /bin) and a developer package with headers and other stuff you only need to compile your own code. See if you find a boost-devel package or something like that

Also, to compile the program, g++ network_task.cpp -o network simply works.

huangapple
  • 本文由 发表于 2023年6月22日 13:31:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76528825.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定