How to use LEDA graph library on Omnet++ projects?

2019-09-14 18:06发布

问题:

I am trying to use LEDA-6.3 library in Omnet++ 4.2.2. I installed LEDA and ran a simple program using it without problem from Ubuntu terminal. However, when I port the code to Omnet++, it fails. Below is my simple code.

    #include <LEDA/graph/graph.h>
    #include <omnetpp.h>

    class cLeda : public cSimpleModule
    {
      protected:
        virtual void initialize();
    };

    Define_Module(cLeda);

    void cLeda::initialize()
    {
        EV << "TestLEDA";
        graph g;
        g.read("nsfnet.txt");
        EV << "No. nodes = " <<g.number_of_nodes() << endl;
    }

I configured for LEDA paths for compiler and linker as follows: Project -> Properties --> Choose C/C++ General -> Path and Symbols and added:

  • For Library Paths: /home/grsst/LEDA-6.3/incl
  • For Libraries: /home/grsst/LEDA-6.3/libleda.a (I didn't add libleda.o since it doesn't work even with Ubuntu command line)
  • For Library Paths: /home/grsst/LEDA-6.3

When I compile, the I got errors as follows:

   Description  Resource    Path    Location    Type
   make: *** [all] Error 2  TestLeda            C/C++ Problem
   make[1]: *** [../out/gcc-debug/src/TestLeda] Error 1 TestLeda            C/C++ Problem
   undefined reference to `leda::graph::~graph()'   cLeda.cc    /TestLeda/src   line 26 C/C++ Problem
   undefined reference to `leda::graph::graph()'    cLeda.cc    /TestLeda/src   line 24 C/C++ Problem
   undefined reference to `leda::graph::read(leda::string)' cLeda.cc    /TestLeda/src   line 25 C/C++ Problem
   undefined reference to `leda::memory_manager_init::~memory_manager_init()'   TestLeda        line 145, external               location: /home/grsst/LEDA-6.3/incl/LEDA/system/memory_std.h   C/C++ Problem
   undefined reference to `leda::memory_manager_init::memory_manager_init()'    TestLeda        line 145, external        location: /home/grsst/LEDA-6.3/incl/LEDA/system/memory_std.h  C/C++ Problem
   undefined reference to `leda::memory_manager::deallocate_bytes(void*, unsigned int)' TestLeda        line 52, external location: /home/grsst/LEDA-6.3/incl/LEDA/internal/handle_types.h  C/C++ Problem
   undefined reference to `leda::std_memory_mgr'    TestLeda        line 52, external        location: /home/grsst/LEDA-6.3/incl/LEDA/internal/handle_types.h   C/C++ Problem
   undefined reference to `leda::string::string(char const*)'   cLeda.cc    /TestLeda/src   line 25 C/C++ Problem

I appreciate any idea to help me to make it work. Thanks a million.

回答1:

OMNeT++ project usually uses Makefile. Try to add LEDA libraries as a Makefrag. Go to Project Properties, choose OMNeT++ | Makemake | select src | Options | Custom | Makefrag and write:

    INCLUDE_PATH += -I/home/grsst/LEDA-6.3/incl
    LIBS += -L/home/grsst/LEDA-6.3  -lleda


标签: omnet++