larkwiot
larkwiot

Reputation: 63

Including read_graphviz_new.cpp from boost 1.73.0 Does Not Compile

I have just downloaded the current latest version of boost (1.73.0), built it, and then copied the headers and libs folders to /usr/local/include. This code does not compile, and spits out tons of errors on redefinitions and functions not being used.

#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;
}

I will edit this question and add any details asked for.

Details: I am using GCC/G++ 10. My full app does use read_graphviz, write_graphviz, and some other BGL stuff and gets the same errors as the edited above.

EDIT I have just found that linking boost regex to my minimal example above makes it work. I am working on replicating the issue in the minimal example now.

Upvotes: 2

Views: 157

Answers (1)

larkwiot
larkwiot

Reputation: 63

Though it may not help other people much, my issue was a typo in an #ifndef that ultimately resulted in the same headers all getting included twice, and for some reason this one was the one that couldn't take it and caused the redefinition bugs. I do still get a note about #pragma message usage, but it compiles.

Upvotes: 1

Related Questions