Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

calling a java funtion from C/CPP. Facing undefined reference to 'JNI_CreateJavaVM'` error in Ubuntu

User_ZHLE1Sep 29 2022

I started working on Apache Iceberg. it is based on JAVA and all of our code is in either C/CPP.
so we are working ideas to interact with Iceberg and we thought JNI can be used, where we can interact with JAVA from C/CPP. But we are seeing issue while comping the code saying undefined reference to 'JNI_CreateJavaVM' , can you check once if I'm missing something.

 g++ -I/usr/lib/jvm/java-11-openjdk-amd64/include  -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux  -L/usr/lib/jvm/java-11-openjdk-amd64/lib/server -L/usr/lib/jvm/java-11-openjdk-amd64/lib  -L/usr/lib/jvm/java-11-openjdk-amd64/jli   -ljvm CTest.cpp
CTest.cpp: In function ‘JNIEnv* create_vm(JavaVM**)’:
CTest.cpp:34:28: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
     options.optionString = "-Djava.class.path=D:\\Java Src\\TestStruct"; //Path to the java source code
                            ^~~~~~~~~~~~~~~~
/tmp/ccOrsCch.o: In function `create_vm(JavaVM_**)':
CTest.cpp:(.text+0x53): undefined reference to `JNI_CreateJavaVM'
collect2: error: ld returned 1 exit status

Below are the path I set:

export PATH=$PATH:/usr/lib/jvm/java-11-openjdk-amd64/lib/
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin

Below is the version details:

my_system@YT-124LGK3:~/jni/c_to_java/CTest$ java --version
openjdk 11.0.16 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu118.04)
OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Ubuntu-0ubuntu118.04, mixed mode, sharing)
Comments
Post Details
Added on Sep 29 2022
0 comments
314 views