0

I have a source file, mything.cpp, and a library that was provided to me as notmine.h and notmine.a.

I need to produce a shared object that has all my stuff from mything.cpp and all the stuff from somelib.a. Here is what I did on the command line:

g++ -fpic -c -o mything.o mything.cpp
g++ -shared -o mything.so mything.o notmine.a

However, when I look at the final mything.so using ldd I see that it has a dependency on libnotmine.so, and when I check nm, I see that all the symbols that should have been supplied by notmine.a are undefined.

What am I doing wrong?


More details: notmine.a is actually liblua.a that I built locally. I think g++ might be getting confused because there is a liblua.so in the system directories

Marco Merlini
  • 875
  • 7
  • 29

1 Answers1

0

Finally figured it out. There are two options. The simpler is to use:

g++ -fpic -c -o mything.o mything.cpp
g++ -shared -o mything.so mything.o -L. -l:notmine.a

Alternatively, you can tell the linker you want to treat the .a as a bunch of object files with

g++ -fpic -c -o mything.o mything.cpp
g++ -shared -o mything.so mything.o -Wl,--whole_archive notmine.a -Wl,--no-whole-archive

The --Wl,-no-whole-archive is to prevent that flag from messing up the other steps the linker does with the system libraries

Marco Merlini
  • 875
  • 7
  • 29