I'm trying to link a .so file with a .so file with no luck in my makefile g++/c++.
Basically I have a bunch of objects I want to use as a library, then I have a shared object I want to link against said library. I try to load the shared object during runtime and I get an undefined symbol error.
Ex:
MyLibraryObjects=LibObject1.o \
LibObject2.o \
LibObject3.o
MyInterfaceObjects=InterfaceObject1.o \
InterfaceObject2.o
CXXFLAGS=-fPIC -shared -I$(MyIncludeDir)
MyLibrary: $(MyLibraryObjects)
g++ -fPIC -shared -o MyLibrary.so $(MyLibraryObjects) -ldl
MyInterface: $(MyInterfaceObjects)
g++ -fPIC -shared -o MyInterface.so MyLibrary.so $(MyInterfaceObjects) -ldl
Then during runtime I load the MyInterface.so and it doesn't recognize LibObject1 constructor.
I can get it working if I do this:
MyInterface: $(MyInterfaceObjects)
g++ -fPIC -shared -o MyInterface.so $(MyInterfaceObjects) $(MyInterfaceObjects) -ldl
But that re-links all the library objects. I would rather link directly against one .so library object. So not sure what to do.
我的.so文件顺序错误,我将其移至末尾并且可以正常工作。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.