I am trying to build, statically link and use two shared libraries one of which calls into the other. For instance lib1.so contains a function lib1_func() that calls into lib2.so's function lib2_func().
In lib1.cpp I have an extern'd function lib1_func() and a header for lib2.so's function, lib2_func().
//lib1.cpp
#include "lib2.h"
extern "C" int lib1_func()
{
return lib2_func();
}
//lib2.h
int lib2_func();
//lib2.cpp
extern "C" int lib2_func()
{
return 100;
}
My question is how do I build and link this properly? As of now I continually receive library not found errors when trying to link lib2.so to lib1.so. Is this the correct way to include lib2 in lib1?
My command line so far is to build lib2.so first then try to build lib1 and link lib2.
g++ -fpic -c lib2.cpp
g++ -shared -o lib2.so lib2.o
g++ -fpic -c lib1.cpp
g++ -shared -o lib1.so lib1.o -L. -llib2
This results in the error
ld: library not found for -llib2
I would appreciate any help on either the fault in my setup or compiler commands. Thank you all in advance.