包含boost 1.73.0中的read_graphviz_new.cpp无法编译

问题描述 投票:0回答:1

我刚刚下载了最新版本的boost(1.73.0),对其进行了构建,然后将标头和libs文件夹复制到/ usr / local / include。该代码无法编译,并且会在未使用的重新定义和函数上吐出大量错误。

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

struct Vertex {
    std::string name;
    std::string label;
    std::string shape;
};

struct Edge {
    std::string label;
};

struct Graph {
    std::string name;
    boost::dynamic_properties props;
};

// https://www.boost.org/doc/libs/1_73_0/libs/graph/doc/using_adjacency_list.html#sec:choosing-graph-type
typedef boost::adjacency_list<
    boost::vecS,
    boost::vecS,
    boost::directedS,

    Vertex,
    Edge,
    Graph
> graph_t;

// pulled from http://insanecoding.blogspot.com/2011/11/how-to-read-in-file-in-c.html
std::string read_file_to_string(std::string fileName) {
    std::ifstream in(fileName, std::ios::in | std::ios::binary);

    if (!in) {
        printf("\n[!] Could not open file %s!\n", fileName.c_str());
        throw(errno);
    }

    std::string contents;
    in.seekg(0, std::ios::end);
    contents.resize(in.tellg());

    in.seekg(0, std::ios::beg);
    in.read(&contents[0], contents.size());

    in.close();
    return contents;
}

using namespace std;

int main() {
    string fileName = "test.dot";
    graph_t graph(0);
    bool ret = -1;

    // https://stackoverflow.com/questions/29898195/boostread-graphviz-how-to-read-out-properties
    // https://stackoverflow.com/questions/29496182/read-graphviz-in-boostgraph-pass-to-constructor/29501850#29501850
    boost::dynamic_properties dp(boost::ignore_other_properties);
    dp.property("node_id", boost::get(&Vertex::name, graph));
    dp.property("label", boost::get(&Vertex::label, graph));
    dp.property("shape", boost::get(&Vertex::shape, graph));
    dp.property("label", boost::get(&Edge::label, graph));

    string contents = read_file_to_string(fileName);
    istringstream stream(contents);

    // https://www.boost.org/doc/libs/1_73_0/libs/graph/doc/read_graphviz.html
    ret = boost::read_graphviz(stream, graph, dp, "node_id");
    if (!ret) {
        printf("[!] Error reading graph!\n");
    }

    graph[boost::graph_bundle].name = fileName;
    graph[boost::graph_bundle].props = dp;

    return 0;
}

我将编辑此问题并添加要求的任何详细信息。

详细信息:我正在使用GCC / G ++10。我的完整应用程序确实使用了read_graphviz,write_graphviz和其他一些BGL东西,并且得到与上面编辑的相同的错误。

编辑我刚刚发现,将boost regex链接到上面的最小示例可以使其正常工作。我现在正在通过最小示例复制问题。

c++ boost boost-graph
1个回答
0
投票

尽管可能对其他人没有太大帮助,但我的问题是#ifndef中的错字,最终导致相同的标头全部包含两次,并且由于某种原因,这个标头无法使用并导致了重新定义错误。我仍然收到有关#pragma消息用法的注释,但可以编译。

© www.soinside.com 2019 - 2024. All rights reserved.