【发布时间】:2018-05-10 23:08:33
【问题描述】:
我正在尝试使用 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);
}
【问题讨论】:
-
g++ -lboost_graph test.cpp是整个编译行吗?请注意,通常库应该在之后需要来自它们的符号的目标文件传递。 -
@VTT 是的,这是整个编译行。
-
@VTT 所以我需要编译成
g++ test.cpp -lboost_graph?