[C++-sig] linking with non-python libraries

Ben Veal benveal92 at hotmail.com
Tue Feb 14 14:22:26 CET 2006


On 2/7/06, Ben Veal <benveal92 at hotmail.com> wrote:

>Hi,
>I am trying to build a python extension for a derived class whose base 
>class I only have as a shared library object & declaration file.
>The base class contains many virtual functions of which I only need a few, 
>and also involves some threading. It contains various functions for getting 
>data from a remote server.
>I manage to build the extension OK (both manually and using pyplusplus), 
>however when I try to import it, I get the following message:
>
>ImportError: /usr/lib/python2.3/MyClient.so: undefined symbol: 
>_ZN8BaseClassC2ERKS_
>
>I suppose it can't find the library containing the base class. I use the 
>following lines in my Jamfile to link with the appropriate libraries:
>
>extension DerivedClass
>:
>    sourcefile.cpp
>     <template>@boost/libs/python/build/extension
>:    <include>/usr/include/BaseClassDir
>     <library-file>/usr/lib/BaseClass.so
>     <lib>/usr/lib/pthread
>     <define>__LINUX
>;
>
>Is is possible to link to a non-python library from a python module?
>If so, what am I doing wrong (surely something simple?).
>If I manage to get over this linking hurdle, is it likely that I will be 
>able to get my extension to work with all the threading?
>
>Thanks.


O.K. problem solved. My own stupid mistake (I'm just a newbie). The base 
class declares it's copy constructor as private. This had caused compilation 
errors when I initially tried to build the extension without pyplusplus, so 
in order to get it to compile I changed the header file of the base class to 
declare the copy constructor as public (under the assumption that class 
member access rules are enforced at compile time only).
So the symbol it couldn't find (_ZN8BaseClassC2ERKS_) was for the now public 
copy constructor.
Changing it back to private, removing the copy constructor from the code 
produced by pyplusplus, and adding boost::noncopyable to the boost.python 
wrapper for the derived class did the job.





More information about the Cplusplus-sig mailing list