我有一个需要用 C++ 编译的库的 Java 程序。为此,我生成了 JNI 头文件,然后使用 JNI 将我的 C++ 应用程序库编译成 .dll。目前,我遇到了一个问题,在链接完成后,我无法运行我的 java 程序。它显示以下错误:
public app.IncClientTester(java.lang.String,java.lang.String,java.lang.String)
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: IncClient.dll: The specified
procedure could not be found
这是我的 Java 代码:
public class IncClientTester extends Tester {
public IncClientTester(String h, String u, String p) {
super(h, u, p);
// TODO Auto-generated constructor stub
}
public native boolean getComponentStatus(int status, int ver);
public native boolean getDeviceThresholdHit();
static {
System.loadLibrary("IncClient");
}
}
这是我的 C++ 代码:
JNIEXPORT jboolean JNICALL Java_app_IncClientTester_getComponentStatus (JNIEnv*, jobject, jint applstat, jint applversion) {
// some code in here
return status // boolean
}
这是我的 C++ Cmakelist.txt:
project(Inc)
cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0015 NEW)
cmake_policy(SET CMP0081 NEW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++0x")
#find_package(vsomeip 2.14.16 REQUIRED)
# Boost
find_package( Boost 1.59 COMPONENTS system thread log REQUIRED )
include_directories( ${Boost_INCLUDE_DIR} )
if(Boost_FOUND)
if(Boost_LIBRARY_DIR)
MESSAGE( STATUS "Boost_LIBRARY_DIR not empty using it: ${Boost_LIBRARY_DIR}" )
else()
if(BOOST_LIBRARYDIR)
MESSAGE( STATUS "Boost_LIBRARY_DIR empty but BOOST_LIBRARYDIR is set setting Boost_LIBRARY_DIR to: ${BOOST_LIBRARYDIR}" )
set(Boost_LIBRARY_DIR ${BOOST_LIBRARYDIR})
endif()
endif()
else()
MESSAGE( STATUS "Boost was not found!")
endif()
message(STATUS "vsomeip is found, version:"${vsomeip_VERSION})
include_directories(
src-gen
capicxx-core-runtime-3.2.0/include
capicxx-someip-runtime-3.2.0/include
vsomeip/interface
"C:/Program Files/Java/jdk1.8.0_261/include"
"C:/Program Files/Java/jdk1.8.0_261/include/win32"
)
link_directories(
capicxx-core-runtime-3.2.0/build/Debug
capicxx-someip-runtime-3.2.0/build/Debug
vsomeip/build/Debug
#/usr/lib
)
# Voltage
add_library(IncClient SHARED
src/IncClient.cpp
src-gen/v1/commonapi/IncSomeIPProxy.cpp
src-gen/v1/commonapi/IncSomeIPDeployment.cpp
)
target_link_libraries(IncClient CommonAPI CommonAPI-SomeIP vsomeip3)
谁能帮我指导我如何解决这个问题。