0

I'm trying to build an app that can invoke java code from c++.

So that I could write something like this

#include<jni.h>

Then do something like this How to access the Java method in a C++ application I have problem adding libraries to CMakeLists.txt Thats what I have now:

cmake_minimum_required(VERSION 3.8)
project(test_cpp_jni)

set(CMAKE_CXX_STANDARD 11)    
include_directories("${JAVA_HOME}/include ${JAVA_HOME}/include/linux")

link_libraries(${JAVA_HOME}/jre/lib/amd64/server/libjvm.so)

set(SOURCE_FILES
    main.cpp
    wrapper/WrapperJNI.cpp
    wrapper/WrapperJNI.h)


add_executable(test_cpp_jni ${SOURCE_FILES})

target_link_libraries(test_cpp_jni ${JAVA_HOME}/jre/lib/amd64/server/libjvm.so)

What shall I correct/add to make this work. Thanks in advance for any help

GrozaiL
  • 101
  • 1
  • 4
  • After long time searching, I found solution! https://stackoverflow.com/questions/7715804/how-to-use-find-jni-on-cmake/7716814#7716814 – GrozaiL Oct 19 '17 at 00:36

1 Answers1

0

You can use the following example to solve your problem:

find_package(JNI)
    if (JNI_FOUND)
        include_directories(SYSTEM ${JAVA_INCLUDE_PATH})
        include_directories(SYSTEM ${JAVA_INCLUDE_PATH2})
    endif()

if (JNI_FOUND)
    target_link_libraries(<example> ${JAVA_JVM_LIBRARY})
endif()
Grant Miller
  • 27,532
  • 16
  • 147
  • 165
lidongze
  • 11
  • 2