Compiling static and shared libraries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello everyone,

I have a library for both static compilation with C++ and a python module (exposed through boost python).  The functionality is split so that everything C++ only is expected to be compiled into a set of static object files that are then wrapped into a single archive file.  The python module must be compiled into a shared object file.  Therefore, the build process builds a *.a for the static stuff and *.so for the python layer.

I'm having issues with bringing the two together.  Here is the compilation lines used for the various parts (excerpt from the makefiles):

# the static archive library makefile is in a different directory from the shared
SOURCES = File1.cpp File2.cpp File3.cpp
outputdir/%.o: %.cpp
	$(CPP) -I/path/for/includes -std=c++0x -c -o $@ $<

outputdir/archive.a:
	ar qc archive.a outputdir/*.o


# the shared object file, *.so
SOURCES = File1.cpp File2.cpp File3.cpp
OBJECTS = $(SOURCES:.cpp=.o)

outputdir/shared.so: $(OBJECTS)
	$(CPP) -o $@ -L/path/to/boost -L/path/to/others -lboost_python -lboost_thread -lboost_regex -Wl,--whole-archive outputdir/archive.a -Wl,--no-whole-archive -fPIC -shared $(OBJECTS)

# compiling each of these objects with fPIC because they are going to into the *.so
outputdir/%.o: %.cpp
	$(CPP) -std=c++0x -c -fPIC $< -o $@


So, as these excerpts show, the static portion of the build is meant to be truly static.  There are many code files which wrap various functionality, as necessary, in order to expose through Python.  All of the object files are built using fPIC as documented above.  Everything builds: that is, both the static object library is built and rolled into an archive.  The shared/dynamic library is built using fPIC and then the static library is brought in using the -Wl,--whole-archive option to ld.  However, when I load up the shared object file in python, I get unresolved symbol errors.  The following is the error that stops the loading of the library:

ImportError: ./shared.so: undefined symbol: _ZN5boost11this_thread5sleepERKNS_10posix_time5ptimeE

Using c++filt, this becomes: boost::this_thread::sleep(boost::posix_time::ptime const&)

This is obviously something haywire with the boost stuff.  Basically, I'd like to make sure that my process is right.  Am I performing the correct steps to include a static object library into a dynamic library?  If so, then it would appear that perhaps ld doesn't know where to find the boost shared objects.  If my process is wrong, however, I need to know how to fix it.

Thanks,
Andy





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux