[PyQt] Simple C++ example has undefined symbol

Gary Fisher gefisher.net at gmail.com
Sun Jan 22 16:57:44 GMT 2012


Hi Jens,

Thank you for getting back to me, much appreciated.
My source code "word.cpp" is attached.

OK, just to make sure we're all on the same page here, this is the
page<http://riverbankcomputing.co.uk/static/Docs/sip4/using.html>
containing
the recipe I'm following.  :-)




        >>> What does "return (static char *)Null" mean?

My mistake...I meant "return (const char *)Null" ... not static....and yes
I do believe NULL is used in C++.  At least the compiler didn't witch at me
for it.


        >>> If you compile C++ code you should use g++ instead of gcc.

I re-ran through the entire example again using g++ instead and I still the
get undefined symbol.  The difference between the two is now
understood...thanks for that.


        >>> Do you have anything in configure.py ....
        >>> for example a line with
        >>> makefile.extra_libs = [ 'word' ]

I do, and exactly as you typed it.


        >>> That will result in the resulting Makefile having '-lword'
        >>> as linker option.

2 little snippets from the resulting makefile follow.  They also show that,
in the making of the library word.so, the linker was indeed aware of the
need to include my little wrapped library libword.so.

LIBS = -lword

$(TARGET): $(OFILES)
@echo '{ global: initword; local: *; };' > word.exp
$(LINK) $(LFLAGS) -o $(TARGET) $(OFILES) $(LIBS)


        >>> I would try ldd word.so

I did and the result show that there is indeed a dependency on the library
libword.so...the one I copied into /usr/lib before doing the make.  ldd
output follows:

linux-gate.so.1 =>  (0x00ffb000)
libword.so => /usr/lib/libword.so (0x00c24000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00110000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0x00c6e000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00206000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00225000)
/lib/ld-linux.so.2 (0x00cf1000)


        >>> I would use 'nm' for such checks
        >>>  Check the letter before the name of the function - if
        >>> it's a 'T' everything is fine (i.e. the symbol is defined in
        >>> that library) but if it's a 'U' the symbol is undefined

When I use "nm -C libword.so" on my little wrapped library I see nothing in
the output to suggest a "word" class or a "reverse" method.  However, when
I run "nm -C word.so" against the library generated by make I get things
like:

000021b4 d methods_Word
         U Word::Word(char const*)
         U Word::reverse() const

among other things.  I can provide complete outputs from both libraries if
needed.

So I'm still stumped and will be researching  why I'm seeing (and not
seeing) these things in the 2 libraries.  Until then, are there any
other ideas out there ?

thanks,
         Gary ---













On Sat, Jan 21, 2012 at 3:51 PM, Jens Thoms Toerring <jt at toerring.de> wrote:

> Hi Gary,
>
> On Sat, Jan 21, 2012 at 08:47:21AM -0500, Gary Fisher wrote:
> > So, I wrote a little C++ class called word and provided a method
> > called reverse which does nothing but "return (static char *)Null".
>
> What does "return (static char *)Null" mean? There's no 'Null'
> in C++ and casting to 'static char pointer also looks rather
> strange (and shouldn't compile since you can't cast to some-
> thing that's 'static'). Do you simply want to return a char
> (NULL) pointer? Then
>
>  return 0;
>
> will be all you need (assuming that the function is defined
> to return a char pointer.
>
> > I then ran "gcc -o libword.so -shared word.cpp" to make my little
> > fictional library (as referred to in the text).
>
> If you compile C++ code you should use g++ instead of gcc.
>
> > I then made the word.sip and configure.py files and ran configure.py.
> > Prior to running make I copied libword.so into /usr/lib so the linker
> would
> > find it.  Running make and 'make install' ran flawless, as did everything
> > until now.
>
> Do you have anything in configure.py that would tell the make
> process that the resulting 'word.so' library will need the
> 'libword.so' library, for example a line with
>
> makefile.extra_libs = [ 'word' ]
>
> That will result in the resulting Makefile having '-lword'
> as linker option.
>
> > At this point, if I understand the theory here, I figured I'd start up a
> > Python command line session and issue the command "import word" and
> > then try "word.reverse()".  To my surprise I got the following error:
> >
> > >>> import word
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> > ImportError: ./word.so: undefined symbol: _ZNK4Word7reverseEv
>
> So 'word.so' is the wrapper library for your original library
> written in C++ (which seems to be 'libword.so'), right? Looks
> to me as if when was 'word.so' created the linker wasn't aware
> that 'libword.so' would be needed when 'word.so' is used.
> 'word.so' is also a library, so the linker will not complain
> when symbols aren't found while 'word.so' is created since
> they're then expected to be found somewhere when the library is
> loaded.
>
> I would try
>
> ldd word.so
>
> If 'libword.so' isn't listed as one of the libraries 'word.so'
> depends on then I would see this as a strong indication that
> my guess isn't completely off the mark.
>
> > I've tried numerous incantations with no luck.  I figured this would work
> > without my having to go and learn all about PyQT just to get it to run.
>
> I don't think it's a problem about PyQt but just of the way
> 'word.so' was created.
>
> > The command "Readelf -s word.so" shows the symbol is listed in the
> > library.
>
> I would use 'nm' for such checks (if you run it with -C it
> will also demangle the strange names the symbols of C++ code
> have). Check the letter before the name of the function - if
> it's a 'T' everything is fine (i.e. the symbol is defined in
> that library) but if it's a 'U' the symbol is undefined and
> thus must be defined somewhere else.
>
>                               Regards, Jens
> --
>  \   Jens Thoms Toerring  ________      jt at toerring.de
>   \_______________________________      http://toerring.de
>



-- 
--------------------------------------------------------------------------------------------------

 “Nothing in all the world is more dangerous than sincere ignorance and
conscientious stupidity.”

 ~ Martin Luther King, Jr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120122/c9d34f33/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: word.cpp
Type: text/x-c++src
Size: 595 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120122/c9d34f33/attachment-0001.cpp>


More information about the PyQt mailing list