Re: R_X86_64_32S error building a shared library - solved
It does prove something about Boost to me - as soon as I add the Boost libraries to the above program I get the error, which implies that something isn't compiled with -fPIC. Since Boost was the only thing added, Boost must have been compiled without -fPIC. As previously mentioned, that's just natural for .a libraries :) Just to follow up on this, I have finally discovered what the problem was. I was installing Boost with Gentoo's "debug" flag enabled, and for some reason this broke all the symlinks - the .so files were pointing at themselves, effectively causing a "file not found" error whenever they were accessed. This meant gcc could not link against the .so files, and apparently in this situation gcc falls back on the .a files, causing the error. I reinstalled Boost without this debug flag, all the symlinks were created properly, and now everything works the way it's supposed to! Thanks everyone for all your help, I really appreciate it. Cheers, Adam.
Re: R_X86_64_32S error building a shared library
$ g++ -fPIC -c -o main.o main.cpp -I/usr/include/boost-1_37/ && g++ -o test.so main.o -shared This works since main.cpp is being compiled to main.o with PIC. However, Boost is not involved here so it proves nothing about Boost. It does prove something about Boost to me - as soon as I add the Boost libraries to the above program I get the error, which implies that something isn't compiled with -fPIC. Since Boost was the only thing added, Boost must have been compiled without -fPIC. Cheers, Adam.
Re: R_X86_64_32S error building a shared library
I have Boost installed on my system as a shared library, so I don't understand why libtool/gcc won't link to it. Hmm okay, I think I've just discovered why - it seems my local installation of Boost was compiled without the -fPIC flag, as I have problems even with trivial compiles, without using automake/libtool: $ g++ -fPIC -c -o main.o main.cpp -I/usr/include/boost-1_37/ && g++ -fPIC -o test.so main.o -shared -lboost_system-mt-1_37 -lboost_filesystem-mt-1_37 /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../x86_64-pc-linux-gnu/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../lib64/libboost_system-mt-1_37.a(error_code.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../lib64/libboost_system-mt-1_37.a: could not read symbols: Bad value collect2: ld returned 1 exit status I think it must have been the way Boost was compiled, because I get the same error even when I don't link to any libraries: $ g++ -c -o main.o main.cpp -I/usr/include/boost-1_37/ && g++ -o test.so main.o -shared /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../x86_64-pc-linux-gnu/bin/ld: main.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC main.o: could not read symbols: Bad value collect2: ld returned 1 exit status But if I add -fPIC in that case, it works: $ g++ -fPIC -c -o main.o main.cpp -I/usr/include/boost-1_37/ && g++ -o test.so main.o -shared Given that I've used -fPIC in the first command above, it would seem that my local installation of Boost was compiled without -fPIC, so it looks like all I need to do is figure out how to do that and everything should work... Thanks for all your help! Cheers, Adam.
Re: R_X86_64_32S error building a shared library
x86_64-pc-linux-gnu/bin/ld: .../lib64/libboost_system-mt-1_37.a(error_code.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC .../lib64/libboost_system-mt-1_37.a: could not read symbols: Bad value You do not need to have boost available as a shared library. Sorry Jan, I don't understand - how can I link my library in with the user's local installation of Boost if it's not available as a shared library? I do not truly have an answer for that. But if I remember correctly, I had seen ".pic.a" libraries previously which, I would say, would alleviate the problem, short of them being much less widespread in use than .a archives already are. It really seems uncommon to me for users not to have shared libraries these days.. Sorry, I should've expressed that more clearly - I didn't think it was possible to link with a user's local installation of Boost if it wasn't in shared-library form. I have Boost installed on my system as a shared library, so I don't understand why libtool/gcc won't link to it. Thanks, Adam.
Re: R_X86_64_32S error building a shared library
x86_64-pc-linux-gnu/bin/ld: .../lib64/libboost_system-mt-1_37.a(error_code.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC .../lib64/libboost_system-mt-1_37.a: could not read symbols: Bad value You do not need to have boost available as a shared library. Sorry Jan, I don't understand - how can I link my library in with the user's local installation of Boost if it's not available as a shared library? Thanks, Adam.
Re: R_X86_64_32S error building a shared library
Hi Ralf, Thanks for your reply, and sorry about taking so long to follow up! x86_64-pc-linux-gnu/bin/ld: .../lib64/libboost_system-mt-1_37.a(error_code.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC .../lib64/libboost_system-mt-1_37.a: could not read symbols: Bad value Please post the full command that causes this (libtool --mode=link ...) including all of its output. This is going to look horrible ;-) Here's the whole compile sequence, one file (main.cpp) being compiled into a shared library (libtest.la) Blank lines added for readability. $ make /bin/sh ../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I. -I.. -I/usr/include/boost-1_37 -fPIC -g -O2 -MT libtest_la-main.lo -MD -MP -MF .deps/libtest_la-main.Tpo -c -o libtest_la-main.lo `test -f 'main.cpp' || echo './'`main.cpp libtool: compile: g++ -DHAVE_CONFIG_H -I. -I.. -I/usr/include/boost-1_37 -fPIC -g -O2 -MT libtest_la-main.lo -MD -MP -MF .deps/libtest_la-main.Tpo -c main.cpp -fPIC -DPIC -o .libs/libtest_la-main.o libtool: compile: g++ -DHAVE_CONFIG_H -I. -I.. -I/usr/include/boost-1_37 -fPIC -g -O2 -MT libtest_la-main.lo -MD -MP -MF .deps/libtest_la-main.Tpo -c main.cpp -o libtest_la-main.o >/dev/null 2>&1 mv -f .deps/libtest_la-main.Tpo .deps/libtest_la-main.Plo /bin/sh ../libtool --tag=CXX --mode=link g++ -g -O2 -L/usr/local/lib -R/usr/local/lib -L/usr/local/lib -R/usr/local/lib -o libtest.la -rpath /usr/local/lib libtest_la-main.lo -lboost_system-mt-1_37 -lboost_filesystem-mt-1_37 libtool: link: g++ -shared -nostdlib /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../lib64/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/crtbeginS.o .libs/libtest_la-main.o -Wl,-rpath -Wl,/usr/local/lib -L/usr/local/lib -lboost_system-mt-1_37 -lboost_filesystem-mt-1_37 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2 -L/ usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/crtendS.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../lib64/crtn.o-Wl,-soname -Wl,libtest.so.0 -o .libs/libtest.so.0.0.0 /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../x86_64-pc-linux-gnu/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../lib64/libboost_system-mt-1_37.a(error_code.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../lib64/libboost_system-mt-1_37.a: could not read symbols: Bad value collect2: ld returned 1 exit status make: *** [libtest.la] Error 1 The $(BOOST_*) variables are set by the "boost.m4" file from the Boost website. This does work fine if I use $(BOOST_*) in my executable, but it doesn't work with the shared library. Please post an URL to the macro file you have downloaded (IIRC there is more than one set of such macros). http://repo.or.cz/w/boost.m4.git (I used the wget command listed on that page) It may be necessary to also see the output of configure The Boost-related part seems fine: checking for Boost headers version >= 103700... /usr/include/boost-1_37 checking for Boost's header version... 1_37 checking for the toolset name used by Boost for g++... gcc43 checking boost/system/error_code.hpp usability... yes checking boost/system/error_code.hpp presence... yes checking for boost/system/error_code.hpp... yes checking for the Boost system library... yes checking boost/filesystem/path.hpp usability... yes checking boost/filesystem/path.hpp presence... yes checking for boost/filesystem/path.hpp... yes checking for the Boost filesystem library... yes checking boost/program_options.hpp usability... yes checking boost/program_options.hpp presence... yes checking for boost/program_options.hpp... yes checking for the Boost program_options library... yes configure: creating ./config.status and/or parts of config.log in order to fully understand what's going on, but I'll be able to ask more specific questions with the information asked above. Let me know what else you need. Like I say it compiles fine into an executable, but not into a shared library. Many thanks, Adam.
R_X86_64_32S error building a shared library
Hi all, I've decided to bite the bullet and finally learn how to use autoconf, and so far I seem to be doing okay except for the final step in the build process. I'm trying to create a shared library, and some code in the library uses Boost. Since users of my library do not have to use Boost in their code, I want my shared library to be linked to the Boost libraries, so that users of my library don't need to link to the Boost libraries themselves. Unfortunately I can't seem to get this to work - I keep getting this error: x86_64-pc-linux-gnu/bin/ld: .../lib64/libboost_system-mt-1_37.a(error_code.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC .../lib64/libboost_system-mt-1_37.a: could not read symbols: Bad value I even tried re-running the commands by hand, adding in -fPIC but I still get the error. Does anyone know what this error means, or how I'm supposed to link other shared libraries in with my own shared library? This is my Makefile.am at the moment: lib_LTLIBRARIES = libtest.la libtest_la_SOURCES = main.cpp $(top_srcdir)/include/gamearchive.hpp libtest_la_CPPFLAGS = $(BOOST_CPPFLAGS) libtest_la_LDFLAGS = $(BOOST_SYSTEM_LDFLAGS) $(BOOST_FILESYSTEM_LDFLAGS) libtest_la_LIBADD = $(BOOST_SYSTEM_LIBS) $(BOOST_FILESYSTEM_LIBS) The $(BOOST_*) variables are set by the "boost.m4" file from the Boost website. This does work fine if I use $(BOOST_*) in my executable, but it doesn't work with the shared library. Any pointers would be much appreciated! Many thanks, Adam.