Passing values from C++ to embedded python.

Mark Rowe bdash at gmx.net
Fri May 31 04:27:08 EDT 2002


>
>
>Thanks a lot Mark,
>
>I have a new problem now though.  :-).  our idea makes sense, I wrote the
>code, I put the stuff in the SWIG interface file, and it compiled perfectly.
>Woohoo.  However, I can't figure out how to link it now.
>
>Here's what I have, simplified:
>
>classtowrap.cpp            # the class i'm trying to wrap
>classtowrap.h                # it's header file
>classtowrap.i                # swig interface file
>classtowrap_wrap.cxx    # generated c++ wrapper class from SWIG
>classtowrap.py                # python shadow class from SWIG
>classtowrapc.so                # the compiled, shared library from the
>classtowrap.cpp and the classtowrap_wrap.cxx that python can import
>
>main.cpp                        # the main driver program
>
>So, the main.cpp is what gets the python interpreter running and needs to
>send the instance into the python namespace.  It, therefore, needs to use
>that method we defined in our classtowrap.i file, which was put in the
>classtowrap_wrap.cxx file, which is now in the shared library
>classtowrapc.so.
>
>I can't, of course, just do a -lclasstowrapc because libraries need to start
>with "lib", so I made a link from libclasstowrapc.so -> classtowrapc.so.
>Now I did the compilation of main.cpp with a -lclasstowrapc at the end of
>it.  Here's the error I got:
>
>ld: libclasstowrapc.dylib is input for the dynamic link editor, is not
>relocatable by the static link editor again
>
>Mac OS X was nice enough to copy my symbolic link, this time with a .dylib
>extension, as is the default for dynamically linked libraries on this OS.
>However, being a dynamic library, you can't statically link it.  So, how DO
>you dynamically link a library?  I've never dealt with this kind of thing
>before.
>
>Thanks again for your help,
>
>Justin Dubs
>

Hello,

I'll start off by saying that I have absolutely no experience with MacOS 
X at all, but am basing this on my other *nix experience.  To compile my 
wrapped class under Linux using GNU G++ I use the following sequence of 
commands:

swig -python -c++ -shadow -o classtowrap_wrap.cpp classtowrap.i
g++ -c -I /usr/include/python2.2 classtowrap_wrap.cpp -o classtowrap_wrap.o
g++ -c classtowrap.cpp -o classtowrap.o
g++ -shared -o libwrapped.so  classtowrap.o classtowrap_wrap.o
g++ -o main main.cpp -l wrapped.so

I've no idea how much of this applies to MacOS X, but I thought I'd try 
and help anyhow :D

Mark






More information about the Python-list mailing list