Linking .jar.so

David Daney ddaney@avtrex.com
Thu Jul 10 22:25:00 GMT 2008


Benjamin de Dardel wrote:
> Hi all,
>> I'm trying to convert .jar to .so and then linking it with a .cpp program.
> Here are the steps I did. I fail to link .o and .so ! May be you have 
> an idea to solve this problem ?
>> Thanks,
> Benjamin
>> >> ERROR
> $ gcj -o essai3.bin essai3.o -L . -lgcj -lstdc++ ant.jar.so 
> ant-launcher.jar.so
> test.o: In function `main':
> test.cpp:22: undefined reference to `void 
> org::apache::tools::ant::Main::main(JArray<java::lang::String*>*)'
> collect2: ld returned 1 exit status
>> >> STEPS
> $ gcj -shared -findirect-dispatch -fjni -fPIC -Wl,-Bsymbolic 
> /opt/ant/lib/ant.jar -o ant.jar.so
> $ gcj -shared -findirect-dispatch -fjni -fPIC -Wl,-Bsymbolic 
> /opt/ant/lib/ant-launcher.jar -o ant-launcher.jar.so
> $ gcjh -v -cni -classpath 
> /opt/ant/lib/ant.jar:/opt/ant/lib/ant-launcher.jar:/usr/lib/jvm/java-6-sun/jre/lib/rt.jar 
> org.apache.tools.ant.Main
> $ g++ -c -g -O -I. test.cpp
> $ gcj -o essai3.bin essai3.o -L . -lgcj -lstdc++ ant.jar.so 
> ant-launcher.jar.so
>> >> Program : test.cpp
> #include <gcj/cni.h>
> #include <java/lang/System.h>
> #include <java/io/PrintStream.h>
> #include <java/lang/Throwable.h>
>> #include <org/apache/tools/ant/Main.h>
>> int main(int argc, char *argv[])
> {
> using namespace java::lang;
>> try
> {
> JvCreateJavaVM(NULL);
> JvAttachCurrentThread(NULL, NULL);
>> String *message = JvNewStringLatin1("Hello from C++");
> JvInitClass(&System::class$);
> System::out->println(message);
> org::apache::tools::ant::Main::main(NULL);
>
You cannot use -findirect-dispatch with CNI like this.
You might be able to use reflection to invoke main, or don't compile the main class with -findirect-dispatch.
> JvDetachCurrentThread();
> }
> catch (Throwable *t)
> {
> System::err->println(JvNewStringLatin1("Unhandled Java 
> exception:"));
> t->printStackTrace();
> }
> }



More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /