[C++-sig] R_X86_64_PC32 error and -fPIC

Gustavo Carneiro gjcarneiro at gmail.com
Sat Aug 16 16:38:28 CEST 2008


2008/8/16 Simon Pickles <sipickles at hotmail.com>

> sorry, that s
>
> Simon Pickles wrote:
>
>> Hi
>>
>> I hope this is on topic. It may be a gcc problem, but its certainly caused
>> by using bjam to link a c++ lib for boost::python. I should point out this
>> whole area is new to me!
>>
>> Here's my error:
>>
>> ...updating 1 target...
>> gcc.link.dll HybridBulletObject.so
>> /usr/bin/ld: HybridModule.o: relocation R_X86_64_PC32 against `(anonymous
>> namespace)::CHybridBulletObject::Init(boost::shared_ptr<CLog>,
>> std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>> const&, unsigned int const&, float const&, float const&, float const&, float
>> const&, float const&, float const&)' can not be used when making a shared
>> object; recompile with -fPIC
>> /usr/bin/ld: final link failed: Bad value
>> collect2: ld returned 1 exit status
>>
>>
>> Compile what with -fPIC? I have an AMD64 (ubuntu 8.04) system. I thought
>> only shared libraries needed to be compiled with PIC, and I am only linking
>> to static libraries in HybridBulletObject.so.
>>
>> So, assuming its talking about the shared library output by bjam, I tried
>> modifying my user-config.jam to:
>>
>> using gcc : : : <linkflags>-fPIC ;
>> using python : 2.5 : /usr/local ; #stackless python location
>>
> sorry, should have been:
>
> using gcc : : : <cxxflags>-fPIC ;
> using python : 2.5 : /usr/local ;
>
> Now, I can see -fPIC on the g++ compile command line. No effect on the
> error tho.
>
> Do I need to rebuild all my static libs with -fPIC too?


If you are building a shared library then all the libraries that you depend
on need to be shared as well, i.e. they all need to be compiled with -fPIC.
You can't link static libraries into shared libraries (the difference
between '.a archive' and 'static library' should be noted here, since you
could have a .a archive containing only objects compiled with -fPIC).


>
>
> I notice that the boost python module will compile and link if I only add
> const functions. Add a normal function and it baulks. Weird.


Not sure what "const function" means.  I only know the concepts of "const
method", and "static function".

-- 
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080816/8412be07/attachment.htm>


More information about the Cplusplus-sig mailing list