2009-06-12 139 views
2

我试图使用read_graphviz扩展来将graphviz .dot文件拖入Boost Grpah。这是我的样品。我无法得到它编译。我在代码后发布了g ++错误消息,但是我不得不这样做,但它很短,在没有显着重新格式化的情况下发布时间太长。无法使用Boost编译代码graphviz.hpp

graphviz.hpp库的文档过于简洁,无法指导我朝着正确的方向前进。任何人有任何想法?

#include <iostream> 
#include <boost/graph/graph_traits.hpp> 
#include <boost/graph/adjacency_list.hpp> 
#include <boost/property_map.hpp> 
#include <boost/graph/graphviz.hpp> 

int main(int argc, char* argv[]) 
{ 
    assert(argc == 2); 

    std::ifstream dotFile(argv[1], std::ifstream::in); 

    typedef boost::adjacency_list<> Graph; 
    Graph graph(17); 

    boost::dynamic_properties properties; 
    boost::property_map< Graph, boost::vertex_name_t >::type name = get(boost::vertex_name, graph); 
    properties.property("node_id", name); 

    bool readResult; 
    readResult = read_graphviz(dotFile, graph, properties); 
    return 0; 

g++ -Wall -c -o graphvizTest.o graphvizTest.cpp 
/usr/include/boost/dynamic_property_map.hpp: In member function 
std::string boost::detail::dynamic_property_map_adaptor<PropertyMap>::get_string(const boost::any&) 
[with PropertyMap = 
boost::vec_adj_list_vertex_property_map< 
    boost::adjacency_list< 
    boost::vecS, boost::vecS, boost::directedS, 
    boost::no_property, boost::no_property, 
    boost::no_property, boost::listS 
    >, 
    boost::adjacency_list< 
    boost::vecS, boost::vecS, boost::directedS, boost::no_property, 
    boost::no_property, boost::no_property, boost::listS 
    >*, 
    boost::detail::error_property_not_found, 
    boost::detail::error_property_not_found&, 
    boost::vertex_name_t 
> 
]':  
graphvizTest.cpp:29: instantiated from here  
/usr/include/boost/dynamic_property_map.hpp:196: error: no match for 'operator<<' in 'out << boost::get 
[with 
PropertyMap = 
boost::vec_adj_list_vertex_property_map< 
    boost::adjacency_list< 
    boost::vecS, boost::vecS, boost::directedS, boost::no_property, boost::no_property, 
    boost::no_property, boost::listS 
    >, 
    boost::adjacency_list< 
    boost::vecS, boost::vecS, boost::directedS, boost::no_property, boost::no_property, 
    boost::no_property, boost::listS 
    >*, 
    boost::detail::error_property_not_found, 
    boost::detail::error_property_not_found&, 
    boost::vertex_name_t 
>, 
Reference = boost::detail::error_property_not_found&, K = long unsigned int 
] 

... 
+1

您没有包含graphvizTest.cpp的第29行.... – 2009-06-12 06:12:43

回答

2

有一个名为您的图形name没有节点属性,因此属性映射你get(boost::vertex_name, graph)得到的是一个错误。查看文档以了解如何为boost::vertex_name(使用旧式属性)添加顶点属性,或者添加一个捆绑属性来表示名称,并在dynamic_properties对象中使用该属性代替get表达式。