Jimmy E Touma | 3 Aug 2004 05:02

Re: .so Library Question

Thanks Criag. I followed your advise and also did the following which
seemed to work (say I have libmylib.so as an external shared library):

g++ -share example3.o example3_wrap.o -L. -lmylib -o _mynewlib.so 

(so now I have one shared lib)
and in python I did

>>> import mynewlib

It works.

Thanks again

On Mon, 2004-08-02 at 19:05, Craig N. Scott wrote:
> When you import the module into python, do you import myexample or
> _myexample (ie with or without underscore)? You should not be using the
> underscored version, which it sounds like you are currently doing. Swig
> should have generated a python file called myexample.py  which will in
> turn import _myexample.so automatically for you. All you should need to
> do is:
> 
> import myexample
> 
> The other thing you may need to do is set your PYTHONPATH to point to
> the directory containing the myexample.py file as well as setting
> LD_LIBRARY_PATH.
> 
> 
> On Tue, 2004-08-03 at 06:21, JE Touma wrote:
> > Hi,
> > 
> > I'm given a shared library (.so) file and a header file to work with. I'm writing
> > a wrapper in C++ and python but I'm not sure how to use the given library. 
> > 
> > Using the approach from the manual, I am doing the following:
> > >> swig -c++ -python myexample.i
> > >> g++ -fPIC -c myexample.cpp myexample_wrap.cxx -I/python_path
> > >> g++ -shared myexample.o myexample_wrap.o -o _myexample.so
> > 
> > 
> > Python is not importing _myexample.so. I have my LD_LIBRARY_PATH set to the
> > current directory and I have my shared library in the same directory with the
> > head file. I guess I am not sure where to link against this library. 
> > 
> > The only way I could figure out how to include the library is that if I had it's
> > object file I could do
> > >> g++ -shared givenlibrary.o myexample.o myexample_wrap.o -o _myexample.so
> > 
> > then import _mylibrary.so into Python. This worked on a sample C++ code. 
> > 
> > Any direction on this matter is greatly appreciated.
> > 
> > Regards,
> > JET

_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig


Gmane