http://www.swig.org/tutorial.html
http://www.dabeaz.com/cgi-bin/wiki.pl?SwigFaqTutorialJavaSharedLibraryExampleOnLinux
http://www.swig.org/Doc2.0/SWIGPlus.html#SWIGPlus_nn2
My inputfile was just the headers of my c++ program (listed twice, as explained in http://mathiasirwans.blogspot.com/2007/11/experience-with-swig-cc-java.html). In the end, I used this bash script to run the whole process (and it was completely successful):
#!/bin/sh
swigFileStem='input'
swigFileExt='swg'
javaLibrary='/usr/lib/jvm/java-6-sun-1.6.0.21'
swig -java -package com.what.ever -c++ ${swigFileStem}.${swigFileExt}
gcc -fpic -c VEGA_Classes.cpp ${swigFileStem}_wrap.cxx -I${javaLibrary}/include -I${javaLibrary}/include/linux
gcc -shared VEGA_Classes.o ${swigFileStem}_wrap.o -lstdc++ -o libvega.so
I hit only a single hitch (at the very last step, trying to run my java program):
Exception in thread "main" java.lang.UnsatisfiedLinkError: PATH/libvega.so: PATH/libvega.so: undefined symbol: _ZTVN10__cxxabiv120__si_class_type_infoE
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1728)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at main.main(main.java:3)
Adding the stdc++ library during the linking via the '-lstdc++' flag you see above fixed the whole problem, as described here: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=193950
Also note the presence of the '-package' tag in my input file. The SWIG manual indicates that the value which follows this flag will appear at the top of each java file produced by SWIG. This is MUCH faster than adding the package declaration yourself. http://www.swig.org/Doc2.0/Java.html
Also note the presence of the '-package' tag in my input file. The SWIG manual indicates that the value which follows this flag will appear at the top of each java file produced by SWIG. This is MUCH faster than adding the package declaration yourself. http://www.swig.org/Doc2.0/Java.html
No comments:
Post a Comment