0

OGDF is a self-contained C++ library for graph algorithms, in particular for (but not restricted to) automatic graph drawing. The latest version of ogdf is called Dogwood (February 2, 2022).

I compiled the file (ex1.cpp) using the command.

g++ -I/home/Desktop/OGDF  -I/home/Desktop/OGDF/include/ogdf  -o ex1.out  -c ex1.cpp

Then the file ex1.out was created in the same directory. I tried to run it by ./ex1.out. But it failed. enter image description here

I am an ogdf beginner and I don't know how to successfully compile and run a c++ program that contains the ogdf library. Although there was a similar post 8 years ago. But it doesn't seem to solve my problem. Probably due to too much time and version updates.

Edit Thanks quentin for the tip. I removed the -c.

g++ -I/home/Desktop/OGDF  -I/home/Desktop/OGDF/include  -o ex1.out  ex1.cpp

But got the following error.

    /tmp/cclq7KEj.o: In function `main':
ex1.cpp:(.text+0x26): undefined reference to `ogdf::Graph::Graph()'
ex1.cpp:(.text+0x2d): undefined reference to `ogdf::GraphAttributes::nodeGraphics'
ex1.cpp:(.text+0x34): undefined reference to `ogdf::GraphAttributes::edgeGraphics'
ex1.cpp:(.text+0x50): undefined reference to `ogdf::GraphAttributes::GraphAttributes(ogdf::Graph const&, long)'
ex1.cpp:(.text+0x80): undefined reference to `ogdf::Graph::newNode()'
ex1.cpp:(.text+0x159): undefined reference to `ogdf::Graph::newNode()'
ex1.cpp:(.text+0x24e): undefined reference to `ogdf::Graph::newEdge(ogdf::NodeElement*, ogdf::NodeElement*)'
ex1.cpp:(.text+0x373): undefined reference to `ogdf::GraphIO::writeGML(ogdf::GraphAttributes const&, std::ostream&)'
ex1.cpp:(.text+0x37e): undefined reference to `ogdf::GraphIO::write(ogdf::GraphAttributes const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool (*)(ogdf::GraphAttributes const&, std::ostream&))'
ex1.cpp:(.text+0x3e8): undefined reference to `ogdf::GraphIO::write(ogdf::GraphAttributes const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool (*)(ogdf::GraphAttributes const&, std::ostream&))'
ex1.cpp:(.text+0x429): undefined reference to `ogdf::Graph::~Graph()'
ex1.cpp:(.text+0x4b9): undefined reference to `ogdf::Graph::~Graph()'
/tmp/cclq7KEj.o: In function `__static_initialization_and_destruction_0(int, int)':
ex1.cpp:(.text+0x525): undefined reference to `ogdf::Initialization::Initialization()'
ex1.cpp:(.text+0x53a): undefined reference to `ogdf::Initialization::~Initialization()'
/tmp/cclq7KEj.o: In function `ogdf::Logger::sfout()':
ex1.cpp:(.text._ZN4ogdf6Logger5sfoutEv[_ZN4ogdf6Logger5sfoutEv]+0x7): undefined reference to `ogdf::Logger::world'
/tmp/cclq7KEj.o: In function `ogdf::NodeArrayBase::~NodeArrayBase()':
ex1.cpp:(.text._ZN4ogdf13NodeArrayBaseD2Ev[_ZN4ogdf13NodeArrayBaseD5Ev]+0x61): undefined reference to `ogdf::Graph::unregisterArray(ogdf::ListIteratorBase<ogdf::NodeArrayBase*, false, false>) const'
/tmp/cclq7KEj.o: In function `ogdf::EdgeArrayBase::~EdgeArrayBase()':
ex1.cpp:(.text._ZN4ogdf13EdgeArrayBaseD2Ev[_ZN4ogdf13EdgeArrayBaseD5Ev]+0x61): undefined reference to `ogdf::Graph::unregisterArray(ogdf::ListIteratorBase<ogdf::EdgeArrayBase*, false, false>) const'
/tmp/cclq7KEj.o: In function `ogdf::GraphAttributes::~GraphAttributes()':
ex1.cpp:(.text._ZN4ogdf15GraphAttributesD2Ev[_ZN4ogdf15GraphAttributesD5Ev]+0xf): undefined reference to `vtable for ogdf::GraphAttributes'
/tmp/cclq7KEj.o: In function `ogdf::GraphIO::drawSVG(ogdf::GraphAttributes const&, std::ostream&)':
ex1.cpp:(.text._ZN4ogdf7GraphIO7drawSVGERKNS_15GraphAttributesERSo[_ZN4ogdf7GraphIO7drawSVGERKNS_15GraphAttributesERSo]+0x1b): undefined reference to `ogdf::GraphIO::svgSettings'
ex1.cpp:(.text._ZN4ogdf7GraphIO7drawSVGERKNS_15GraphAttributesERSo[_ZN4ogdf7GraphIO7drawSVGERKNS_15GraphAttributesERSo]+0x26): undefined reference to `ogdf::GraphIO::drawSVG(ogdf::GraphAttributes const&, std::ostream&, ogdf::GraphIO::SVGSettings const&)'
/tmp/cclq7KEj.o: In function `ogdf::List<ogdf::GenericPoint<double> >::operator delete(void*, unsigned long)':
ex1.cpp:(.text._ZN4ogdf4ListINS_12GenericPointIdEEEdlEPvm[_ZN4ogdf4ListINS_12GenericPointIdEEEdlEPvm]+0x48): undefined reference to `ogdf::PoolMemoryAllocator::deallocate(unsigned long, void*)'
/tmp/cclq7KEj.o: In function `ogdf::ListPure<ogdf::GenericPoint<double> >::clear()':
ex1.cpp:(.text._ZN4ogdf8ListPureINS_12GenericPointIdEEE5clearEv[_ZN4ogdf8ListPureINS_12GenericPointIdEEE5clearEv]+0x32): undefined reference to `ogdf::PoolMemoryAllocator::deallocateList(unsigned long, void*, void*)'
/tmp/cclq7KEj.o: In function `ogdf::ListPure<ogdf::GenericPoint<double> >::operator delete(void*, unsigned long)':
ex1.cpp:(.text._ZN4ogdf8ListPureINS_12GenericPointIdEEEdlEPvm[_ZN4ogdf8ListPureINS_12GenericPointIdEEEdlEPvm]+0x48): undefined reference to `ogdf::PoolMemoryAllocator::deallocate(unsigned long, void*)'
/tmp/cclq7KEj.o: In function `ogdf::ListElement<ogdf::GenericPoint<double> >::operator new(unsigned long)':
ex1.cpp:(.text._ZN4ogdf11ListElementINS_12GenericPointIdEEEnwEm[_ZN4ogdf11ListElementINS_12GenericPointIdEEEnwEm]+0x2d): undefined reference to `ogdf::PoolMemoryAllocator::allocate(unsigned long)'
/tmp/cclq7KEj.o: In function `ogdf::EdgeArray<ogdf::GenericPolyline<ogdf::GenericPoint<double> > >::operator delete(void*, unsigned long)':
ex1.cpp:(.text._ZN4ogdf9EdgeArrayINS_15GenericPolylineINS_12GenericPointIdEEEEEdlEPvm[_ZN4ogdf9EdgeArrayINS_15GenericPolylineINS_12GenericPointIdEEEEEdlEPvm]+0x48): undefined reference to `ogdf::PoolMemoryAllocator::deallocate(unsigned long, void*)'
/tmp/cclq7KEj.o: In function `ogdf::NodeArray<int>::operator delete(void*, unsigned long)':
ex1.cpp:(.text._ZN4ogdf9NodeArrayIiEdlEPvm[_ZN4ogdf9NodeArrayIiEdlEPvm]+0x48): undefined reference to `ogdf::PoolMemoryAllocator::deallocate(unsigned long, void*)'
/tmp/cclq7KEj.o: In function `ogdf::NodeArray<double>::operator delete(void*, unsigned long)':
ex1.cpp:(.text._ZN4ogdf9NodeArrayIdEdlEPvm[_ZN4ogdf9NodeArrayIdEdlEPvm]+0x48): undefined reference to `ogdf::PoolMemoryAllocator::deallocate(unsigned long, void*)'
/tmp/cclq7KEj.o: In function `ogdf::NodeArray<ogdf::Shape>::operator delete(void*, unsigned long)':
ex1.cpp:(.text._ZN4ogdf9NodeArrayINS_5ShapeEEdlEPvm[_ZN4ogdf9NodeArrayINS_5ShapeEEdlEPvm]+0x48): undefined reference to `ogdf::PoolMemoryAllocator::deallocate(unsigned long, void*)'
/tmp/cclq7KEj.o: In function `ogdf::NodeArray<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::operator delete(void*, unsigned long)':
ex1.cpp:(.text._ZN4ogdf9NodeArrayINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEdlEPvm[_ZN4ogdf9NodeArrayINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEdlEPvm]+0x48): undefined reference to `ogdf::PoolMemoryAllocator::deallocate(unsigned long, void*)'
/tmp/cclq7KEj.o:ex1.cpp:(.text._ZN4ogdf9NodeArrayINS_6StrokeEEdlEPvm[_ZN4ogdf9NodeArrayINS_6StrokeEEdlEPvm]+0x48): more undefined references to `ogdf::PoolMemoryAllocator::deallocate(unsigned long, void*)' follow

I don't know if I need to add more additional dependencies. I have read the build guide of odgf below. When I run it, it still reports an error.

 c++ -I/home/Desktop/OGDF  -I/home/Desktop/OGDF/include/ogdf  -o ex1.o  -c ex1.cpp
c++ -o output_binary -L/home/Desktop/OGDF  ex1.o -lOGDF -lCOIN

Say OGDF and COIN cannot be found.


 //ex1.cpp
#include <ogdf/basic/GraphAttributes.h>
#include <ogdf/fileformats/GraphIO.h>   
using namespace ogdf;    
int main() {
    Graph G;
    GraphAttributes GA(G,
                       GraphAttributes::nodeGraphics | GraphAttributes::edgeGraphics);

    const int LEN = 11;
    for (int i = 1; i < LEN; ++i) {
        node left = G.newNode();
        GA.x(left) = -5 * (i + 1);
        GA.y(left) = -20 * i;
        GA.width(left) = 10 * (i + 1);
        GA.height(left) = 15;

        node bottom = G.newNode();
        GA.x(bottom) = 20 * (LEN - i);
        GA.y(bottom) = 5 * (LEN + 1 - i);
        GA.width(bottom) = 15;
        GA.height(bottom) = 10 * (LEN + 1 - i);

        edge e = G.newEdge(left, bottom);
        DPolyline &p = GA.bends(e);
        p.pushBack(DPoint(10, -20 * i));
        p.pushBack(DPoint(20 * (LEN - i), -10));
    }

    GraphIO::write(GA, "output-manual.gml", GraphIO::writeGML);
    GraphIO::write(GA, "output-manual.svg", GraphIO::drawSVG);

    return 0;
}
licheng
  • 115
  • 5
  • Drop the `-c` flag, it's telling GCC to produce an intermediate object file and *not* link it into a finished executable. – Quentin Jul 23 '22 at 14:14
  • Thank you very much, I removed the `-c`. but it still shows an error. I feel I need to add some dependencies. But I don't know how to add. (For specific information, I have added inside the post). – licheng Jul 23 '22 at 15:21

0 Answers0