Tutorial Swig 2.0.9 and Ubuntu12.10(64bit)
Now, swig tutorial is as follows. (http://www.swig.org/tutorial.html)
Building a Python module
$ sudo apt-get install python3.2-dev-all
$ swig -python example.i
$ gcc -c example.c example_wrap.c -I/usr/include/python3.2 -fPIC
$ ld -shared example.o example_wrap.o -o _example.so
Building a Python module
$ sudo apt-get install python3.2-dev-all
$ swig -python example.i
$ gcc -c example.c example_wrap.c -I/usr/include/python3.2 -fPIC
$ ld -shared example.o example_wrap.o -o _example.so
$ python3.2
Python 3.2.3 (default, Oct 19 2012, 19:53:16)
Python 3.2.3 (default, Oct 19 2012, 19:53:16)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import example
>>> example.fact(5)
120
>>> example.my_mod(7,3)
1
>>> example.get_time()
'Sun Mar 31 11:48:42 2013\n'
>>>
If you do not specify the '-fPIC' of options to the compiler, the following error occurs in GNU/Linux(ELF system).
$ ld -shared example.o example_wrap.o -o _example.so
ld: example_wrap.o: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
example_wrap.o: could not read symbols: Bad value
コメント
コメントを投稿