0

I have pre-written functions from another project that I want to include as part of my simulations. I have the object file (functions.a) and the header file (functions.h) of these functions.

In a normal C/C++ project, I was able to import them using the steps outlined in this answer. However, my project was created as an OMNeT++ project and it appears the C/C++ Build -> Settings -> GCC C Linker -> Miscellaneous properties are not made available.

Is there a way to access these properties or another alternative to import object files in an OMNeT project?

EDIT

I tried adding

EXTRA_OBJS += -L/home/jacques/omnetpp-6.0pre10/workspace/model1t2/externalObjects/HM4 -lfunctions
CFLAGS += -I/home/jacques/omnetpp-6.0pre10/workspace/model1t2/externalObjects/include

But I am getting the error below

make MODE=release V=1 all 
cd src && make
make[1]: Entering directory '/home/jacques/omnetpp-6.0pre10/workspace/model1t2/src'
Creating executable: ../out/clang-release/src/model1t2
clang++   -fuse-ld=lld -Wl,-rpath,/home/jacques/omnetpp-6.0pre10/lib -Wl,-rpath,/lib -Wl,-rpath,.  -Wl,--export-dynamic -L/home/jacques/omnetpp-6.0pre10/lib -o ../out/clang-release/src/model1t2 ../out/clang-release/src/M1M.o ../out/clang-release/src/M1M_m.o  -L/home/jacques/omnetpp-6.0pre10/workspace/model1t2/externalObjects/HM4 -lfunctions -Wl,--no-as-needed -Wl,--whole-archive  -Wl,--no-whole-archive -loppmain -Wl,-u,_cmdenv_lib -Wl,--no-as-needed -loppcmdenv -loppenvir -Wl,-u,_qtenv_lib -Wl,--no-as-needed -Wl,-rpath-link=/usr/lib/x86_64-linux-gnu -loppqtenv -loppenvir -lopplayout  -loppsim -ldl -lstdc++ 
ld.lld: error: unable to find library -lfunctions
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [Makefile:100: ../out/clang-release/src/model1t2] Error 1
make[1]: Leaving directory '/home/jacques/omnetpp-6.0pre10/workspace/model1t2/src'
make: *** [Makefile:2: all] Error 2
"make MODE=release V=1 all" terminated with exit code 2. Build might be incomplete.
Jacques
  • 13
  • 4

1 Answers1

0

OMNeT++ project uses Makefile, therefore to add an external library or class one should modify makefrag.
You should go to Project | Properties | OMNeT++ | Makemake | select root or src of your project | Options, then Custom | Makefrag and write the following lines:

EXTRA_OBJS += -LD:/foo/lib -lfunctions
CFLAGS += -ID:/foo/include

where D:/foo/lib is an example of Windows directory which contains a library (e.g. libfunctions.a), and D:/foo/include - header files.

Jerzy D.
  • 6,707
  • 2
  • 16
  • 22
  • I followed the steps you outlined, but keep getting this error `ld.lld: error: unable to find library -lfunctions`. I turned the verbose mode with `V=1`, but it didn't help. Just to make sure, I enter this in the field `fragment to be inserted into Makefile`? I don't have `makefrag` under custom. If it helps, I am on omnet-6.0pre10 on Ubuntu – Jacques Apr 08 '21 at 16:39
  • Could you show your entries in Makefrag as well as path of libfunctions.a? – Jerzy D. Apr 08 '21 at 17:17
  • I have the following `markfrag` file in my src folder `EXTRA_OBJS += -L/home/jacques/omnetpp-6.0pre10/workspace/model1t2/externalObjects/HM4 -lfunctions` and `CFLAGS += -I/home/jacques/omnetpp-6.0pre10/workspace/model1t2/externalObjects/inlcude` My file functions.a is in the path `/home/jacques/omnetpp-6.0pre10/workspace/model1t2/externalObjects/HM4/functions.a` – Jacques Apr 08 '21 at 17:22
  • Change `functions.a` into `libfunctions.a`. – Jerzy D. Apr 08 '21 at 17:25
  • I made the change and tried both `-lfunctions` and `-llibfunctions` in `markfrag` and got the same error. – Jacques Apr 08 '21 at 17:35
  • Set `V=1` and show lines that generate error (from console). – Jerzy D. Apr 08 '21 at 17:47
  • I added the complete error message in the answer. It was too long for a comment. – Jacques Apr 08 '21 at 18:00
  • I ended up starting a new project as I had played a lot with the setting trying to solve the error. Using the factory setting, following your answer and changing `functions.a` to `libfunctions.a` and adding `-lfunctions` to `marfrag` solved it. Sorry I can't upvote, not enough reputation. Thanks! – Jacques Apr 08 '21 at 18:40