Tuesday, 27 August 2013

undefined symbol: JNI_CreateJavaVM in Linux

undefined symbol: JNI_CreateJavaVM in Linux

I got 2 projects. both are created in Netbeans IDE on Ubuntu 64 bit.
first, my .so project implements calling Java function from its c++ codes.
and my console application try to call functions in .so file.
I got an error as following when I compiles and run:
/home/online0227/desktop/jvm run/dist/Debug/GNU-Linux-x86/jvm_run: symbol
lookup error: ./libjvm_dll.so: undefined symbol: JNI_CreateJavaVM
How to resolve this?
I included include path to my .so project. Here is what my netbeans shows
on its build output when I compile .so project:
g++ -c -g -I/home/online0227/jdk1.7.0_25_x64/include/linux
-I/home/online0227/jdk1.7.0_25_x64/include -fPIC -MMD -MP -MF
build/Debug/GNU-Linux-x86/_ext/1117207477/testlib.o.d -o
build/Debug/GNU-Linux-x86/_ext/1117207477/testlib.o
/home/online0227/desktop/jvm\ dll/testlib.cpp
g++ -o dist/Debug/GNU-Linux-x86/libjvm_dll.so
build/Debug/GNU-Linux-x86/_ext/1117207477/testlib.o -shared -fPIC
this .so compiles very well and produces .so file.
And here is what my Netbeans shows when I compile my main console
application:
g++ -c -g -I/home/online0227/jdk1.7.0_25_x64/include/linux
-I/home/online0227/jdk1.7.0_25_x64/include -MMD -MP -MF
build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o
main.cpp
g++ -o dist/Debug/GNU-Linux-x86/jvm_run
build/Debug/GNU-Linux-x86/main.o
-L/home/online0227/jdk1.7.0_25_x64/jre/lib/amd64/server -ldl -ljvm
It also compiles very well and run.
But the problem is I get an error message when I try to create Java
Virtual Machine, "JNI_CreateJavaVM(&jvm, reinterpret_cast(&env),
&vm_args)".
And following are all my source codes,
for .so project's testLib.h:
#ifndef TESTLIB_H
#define TESTLIB_H
class TestLib : public TestVir
{
public:
void init();
int createJVM();
};

No comments:

Post a Comment