英文:
Couldn't find boost folders in '/usr/include' and '/usr/local/include' when installed using "sudo dnf -y install boost"
问题
我对CPP中的附加库相对陌生,并且正在使用CentOS 8.5.2111和GCC 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<iostream>
#include<boost/graph/adjacency_list.hpp>
using namespace std;
int main(){
cout<<"Hello World!";
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<boost/graph/adjacency_list.hpp>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论