gpt4 book ai didi

c++ - 在 boost 中从 graphviz 读取的问题

转载 作者:行者123 更新时间:2023-11-30 05:01:29 25 4
gpt4 key购买 nike

我正在尝试使用 boost 的 graphviz 阅读下图:

graph G {
0[label="1"];
1[label="0"];
2[label="1"];
3[label="1"];
0--1 [label="1.2857"];
1--2 [label="4.86712"];
1--3 [label="2.29344"];
}

但是,每次我尝试编译它时,我都会遇到一个严重的错误:

/tmp/ccnZnPad.o: In function "bool boost::read_graphviz_new<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, Vertex, Edge, boost::no_property, boost::listS> >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, Vertex, Edge, boost::no_property, boost::listS>&, boost::dynamic_properties&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):test.cpp(.text._ZN5boost17read_graphviz_newINS_14adjacency_listINS_4vecSES2_NS_11undirectedSE6Vertex4EdgeNS_11no_propertyENS_5listSEEEEEbRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERT_RNS_18dynamic_propertiesESG_[_ZN5boost17read_graphviz_newINS_14adjacency_listINS_4vecSES2_NS_11undirectedSE6Vertex4EdgeNS_11no_propertyENS_5listSEEEEEbRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERT_RNS_18dynamic_propertiesESG_]+0x98): undefined reference to boost::detail::graph::read_graphviz_new(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::detail::graph::mutate_graph*)'
collect2: error: ld returned 1 exit status

我不知道这是什么意思,我试过用 g++ -lboost_graph test.cpp 编译我仍然得到错误。我也尝试包括 <libs/graph/src/read_graphviz_new.cpp>但后来我的程序中断了,因为它不知道是什么 <libs/graph/src/read_graphviz_new.cpp>是。我不知道下一步需要尝试什么,或者这可能不是打印出来的正确方法。任何帮助将不胜感激!

#include <fstream>

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/property_map/dynamic_property_map.hpp>
//#include <libs/graph/src/read_graphviz_new.cpp> //breaks if I try to include
#include <boost/graph/graph_utility.hpp>

struct Vertex
{
bool isLeaf;
};

struct Edge
{
double weight;
};

typedef boost::adjacency_list<boost::vecS,boost::vecS, boost::undirectedS, Vertex, Edge> Graph;

int main()
{
Graph g;
boost::dynamic_properties dp;
dp.property("label", get(&Vertex::isLeaf, g));
dp.property("label", get(&Edge::weight, g));

std::ifstream dot("baseTree.dot");

boost::read_graphviz(dot,g,dp);
write_graphviz_dp(std::cout, g, dp);
}

最佳答案

read_graphviz 实现在库部分(已编译),因此您需要以某种方式链接它。

您可以直接编译并链接相关的 cpp 文件,甚至将其包含到您的文件中:

#include <libs/graph/src/read_graphviz_new.cpp>

“规范”方式是编译库和链接,例如与

g++ test.cpp -lboost_graph 

是的,顺序很重要! ( Why does the order of '-l' option in gcc matter? )

关于c++ - 在 boost 中从 graphviz 读取的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50282741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com