Re: Compiling static and shared libraries

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

 



On 29 April 2013 17:27, Andy Falanga (afalanga) wrote:
> # 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.

Does 'ldd shared.so' show any dependency on libboost_thread.so?  (I'm
assuming no)

Have you tried fixing the link line so that the libraries are listed
after the objects that depend on them?

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





[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