无法 link Boost Graph Library 用于 read_graphviz() 示例
Can not link Boost Graph Library for read_graphviz() example
我正在尝试用 read_graphviz 做一个例子,但我无法帮助 linker link read_graphviz 函数调用正确的版本 read_graphviz.
在 http://www.boost.org/doc/libs/1_61_0/libs/graph/doc/read_graphviz.html 有 read_graphviz 的三个模板版本:
命名空间提升 {
template <typename MutableGraph>
bool read_graphviz(std::istream& in, MutableGraph& graph,
dynamic_properties& dp,
const std::string& node_id = "node_id");
template <typename MutableGraph>
bool read_graphviz(std::string& str, MutableGraph& graph,
dynamic_properties& dp,
const std::string& node_id = "node_id");
template <typename InputIterator, typename MutableGraph>
bool read_graphviz(InputIterator begin, InputIterator end,
MutableGraph& graph, dynamic_properties& dp,
const std::string& node_id = "node_id");
}
我正在尝试调用它的第二个版本。
这是我的示例代码:
#include <boost/graph/graphviz.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/property_map/dynamic_property_map.hpp>
#include <boost/graph/graph_utility.hpp>
using namespace boost;
typedef boost::adjacency_list <
boost::vecS,
boost::vecS,
boost::undirectedS,
boost::property<boost::vertex_index_t, int>,
boost::property<boost::edge_index_t, int>> Graph;
int main(int argc, char** argv)
{
Graph dual_g;
boost::dynamic_properties dp;
boost::property_map<Graph, boost::vertex_index_t>::type vIndex = get(boost::vertex_index, dual_g);
dp.property("vertex_id",vIndex);
boost::property_map<Graph, boost::edge_index_t>::type eIndex = get(boost::edge_index, dual_g);
dp.property("edge_id", eIndex);
read_graphviz("dtest.dot", dual_g , dp); //, "node_id");
return 0;
}
我尝试使用以下命令进行编译:
g++ -std=c++11 main.cpp -o main -lboost_system
错误:
/tmp/cctwokpF.o: In function `bool boost::read_graphviz_new<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::property<boost::vertex_index_t, int, boost::no_property>, boost::property<boost::edge_index_t, int, boost::no_property>, 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, boost::property<boost::vertex_index_t, int, boost::no_property>, boost::property<boost::edge_index_t, int, boost::no_property>, boost::no_property, boost::listS>&, boost::dynamic_properties&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
main.cpp:(.text._ZN5boost17read_graphviz_newINS_14adjacency_listINS_4vecSES2_NS_11undirectedSENS_8propertyINS_14vertex_index_tEiNS_11no_propertyEEENS4_INS_12edge_index_tEiS6_EES6_NS_5listSEEEEEbRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERT_RNS_18dynamic_propertiesESJ_[_ZN5boost17read_graphviz_newINS_14adjacency_listINS_4vecSES2_NS_11undirectedSENS_8propertyINS_14vertex_index_tEiNS_11no_propertyEEENS4_INS_12edge_index_tEiS6_EES6_NS_5listSEEEEEbRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERT_RNS_18dynamic_propertiesESJ_]+0x80): 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
您需要link执行功能。
最简单的方法是包含它:
#include <libs/graph/src/read_graphviz_new.cpp>
如果您喜欢更多示例以获取灵感:read_graphviz src
我正在尝试用 read_graphviz 做一个例子,但我无法帮助 linker link read_graphviz 函数调用正确的版本 read_graphviz.
在 http://www.boost.org/doc/libs/1_61_0/libs/graph/doc/read_graphviz.html 有 read_graphviz 的三个模板版本: 命名空间提升 {
template <typename MutableGraph>
bool read_graphviz(std::istream& in, MutableGraph& graph,
dynamic_properties& dp,
const std::string& node_id = "node_id");
template <typename MutableGraph>
bool read_graphviz(std::string& str, MutableGraph& graph,
dynamic_properties& dp,
const std::string& node_id = "node_id");
template <typename InputIterator, typename MutableGraph>
bool read_graphviz(InputIterator begin, InputIterator end,
MutableGraph& graph, dynamic_properties& dp,
const std::string& node_id = "node_id");
}
我正在尝试调用它的第二个版本。 这是我的示例代码:
#include <boost/graph/graphviz.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/property_map/dynamic_property_map.hpp>
#include <boost/graph/graph_utility.hpp>
using namespace boost;
typedef boost::adjacency_list <
boost::vecS,
boost::vecS,
boost::undirectedS,
boost::property<boost::vertex_index_t, int>,
boost::property<boost::edge_index_t, int>> Graph;
int main(int argc, char** argv)
{
Graph dual_g;
boost::dynamic_properties dp;
boost::property_map<Graph, boost::vertex_index_t>::type vIndex = get(boost::vertex_index, dual_g);
dp.property("vertex_id",vIndex);
boost::property_map<Graph, boost::edge_index_t>::type eIndex = get(boost::edge_index, dual_g);
dp.property("edge_id", eIndex);
read_graphviz("dtest.dot", dual_g , dp); //, "node_id");
return 0;
}
我尝试使用以下命令进行编译:
g++ -std=c++11 main.cpp -o main -lboost_system
错误:
/tmp/cctwokpF.o: In function `bool boost::read_graphviz_new<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::property<boost::vertex_index_t, int, boost::no_property>, boost::property<boost::edge_index_t, int, boost::no_property>, 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, boost::property<boost::vertex_index_t, int, boost::no_property>, boost::property<boost::edge_index_t, int, boost::no_property>, boost::no_property, boost::listS>&, boost::dynamic_properties&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
main.cpp:(.text._ZN5boost17read_graphviz_newINS_14adjacency_listINS_4vecSES2_NS_11undirectedSENS_8propertyINS_14vertex_index_tEiNS_11no_propertyEEENS4_INS_12edge_index_tEiS6_EES6_NS_5listSEEEEEbRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERT_RNS_18dynamic_propertiesESJ_[_ZN5boost17read_graphviz_newINS_14adjacency_listINS_4vecSES2_NS_11undirectedSENS_8propertyINS_14vertex_index_tEiNS_11no_propertyEEENS4_INS_12edge_index_tEiS6_EES6_NS_5listSEEEEEbRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERT_RNS_18dynamic_propertiesESJ_]+0x80): 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
您需要link执行功能。
最简单的方法是包含它:
#include <libs/graph/src/read_graphviz_new.cpp>
如果您喜欢更多示例以获取灵感:read_graphviz src