Undefined reference to class definition ??

Hi

I have successfully built OGDF under directory undefined reference to /home/vijay13/Downloads/OGDF-snapshot/

I have following code in test.cpp under directory /home/vijay13/Downloads/ :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#include <ogdf/basic/Graph.h>
#include <ogdf/fileformats/GraphIO.h>
#include <ogdf/basic/graph_generators.h>
#include <ogdf/layered/DfsAcyclicSubgraph.h>

using namespace ogdf;

int main()
{
        Graph G;
        randomSimpleGraph(G, 10, 20);
        DfsAcyclicSubgraph DAS;
        DAS.callAndReverse(G);
        GraphIO::writeGML(G,"test.gml");

        return 0;
}


while compiling as following :
1
2
vijay13@ubuntu:~/Downloads$ g++ -o test test.cpp -I /home/vijay13/Downloads/OGDF-snapshot/include/


I am getting following error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
vijay13@ubuntu:~/Downloads$ g++ -o test test.cpp -I /home/vijay13/Downloads/OGDF-snapshot/include/
/tmp/ccPE8nCu.o: In function `main':
test.cpp:(.text+0x26): undefined reference to `ogdf::Graph::Graph()'
test.cpp:(.text+0x3f): undefined reference to `ogdf::randomSimpleGraph(ogdf::Graph&, int, int)'
test.cpp:(.text+0x67): undefined reference to `ogdf::AcyclicSubgraphModule::callAndReverse(ogdf::Graph&)'
test.cpp:(.text+0x7b): undefined reference to `ogdf::GraphIO::writeGML(ogdf::Graph const&, char const*)'
test.cpp:(.text+0x9e): undefined reference to `ogdf::Graph::~Graph()'
test.cpp:(.text+0xd7): undefined reference to `ogdf::Graph::~Graph()'
/tmp/ccPE8nCu.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x139): undefined reference to `ogdf::Initialization::Initialization()'
test.cpp:(.text+0x13e): undefined reference to `ogdf::Initialization::~Initialization()'
/tmp/ccPE8nCu.o: In function `ogdf::DfsAcyclicSubgraph::DfsAcyclicSubgraph()':
test.cpp:(.text._ZN4ogdf18DfsAcyclicSubgraphC2Ev[_ZN4ogdf18DfsAcyclicSubgraphC5Ev]+0x1f): undefined reference to `vtable for ogdf::DfsAcyclicSubgraph'
/tmp/ccPE8nCu.o: In function `ogdf::DfsAcyclicSubgraph::~DfsAcyclicSubgraph()':
test.cpp:(.text._ZN4ogdf18DfsAcyclicSubgraphD2Ev[_ZN4ogdf18DfsAcyclicSubgraphD5Ev]+0x13): undefined reference to `vtable for ogdf::DfsAcyclicSubgraph'
collect2: ld returned 1 exit status


Please Please help me solve this.
Thanks in advance
Last edited on
nolyc wrote:
Undefined reference is a linker error.
It's not a compile error. #includes don't help.
You did not define the thing in the error message, you forgot to link the file that defines it, you forgot to link to the library that defines it, or, if it's a static library, you have the wrong order on the linker command line.
Check which one. (Note that some linkers call it an unresolved external)
@ne555 thank you very much your advise helped really well.
Topic archived. No new replies allowed.