user1673206
user1673206

Reputation: 1711

making boost work (visual studio 2010 windows 2007)

Im trying to use boost on visual studio 2010 on windows 7. I followed this great explanation here- link. but with no success.

I get a lot of errors:

1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(20): error C2143: syntax error : missing ';' before '<'
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(22): error C2065: 'Graph' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(22): error C2146: syntax error : missing ';' before identifier 'G'
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(22): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(23): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(23): error C3861: 'add_edge': identifier not found
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(24): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(24): error C3861: 'add_edge': identifier not found
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(25): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(25): error C3861: 'add_edge': identifier not found
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(26): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(26): error C3861: 'add_edge': identifier not found
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(28): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(28): error C3861: 'num_vertices': identifier not found
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(29): error C2065: 'G' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\scenarioanalyzer\scenarioanalyzer\main.cpp(29): error C3861: 'connected_components': identifier not found 

this is the code example im trying to build:

#include <algorithm>
#include <utility>
#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>

void main()
{
    typedef adjacency_list <vecS, vecS, undirectedS> Graph;

    Graph G;
    add_edge(0, 1, G);
    add_edge(1, 4, G);
    add_edge(4, 0, G);
    add_edge(2, 5, G);

    std::vector<int> component(num_vertices(G));
    int num = connected_components(G, &component[0]);

    std::vector<int>::size_type i;
    cout << "Total number of components: " << num << endl;
    for (i = 0; i != component.size(); ++i)
      cout << "Vertex " << i <<" is in component " << component[i] << endl;
    cout << endl;
}

I will be happy for some help, thanks.

Upvotes: 2

Views: 112

Answers (1)

sehe
sehe

Reputation: 393759

You're missing several usings or namespace declarations. Also missing: #include <iostream>

I'd suggest using namespace boost and std:: qualifications:

Live On Coliru

#include <algorithm>
#include <utility>
#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>
#include <iostream>

using namespace boost;

int main()
{
    typedef adjacency_list <vecS, vecS, undirectedS> Graph;

    Graph G;
    add_edge(0, 1, G);
    add_edge(1, 4, G);
    add_edge(4, 0, G);
    add_edge(2, 5, G);

    std::vector<int> component(num_vertices(G));
    int num = connected_components(G, &component[0]);

    std::vector<int>::size_type i;
    std::cout << "Total number of components: " << num << std::endl;
    for (i = 0; i != component.size(); ++i)
        std::cout << "Vertex " << i <<" is in component " << component[i] << std::endl;
    std::cout << std::endl;
}

Upvotes: 2

Related Questions