Still new to android and java but learning more each day :)
This question refers to
Ok, the error refers to
expression failed to parse:
error: <user expression 27>:1:1: 'bl' has unknown type; cast it to its declared type to use it
bl
^~
and
expression failed to parse:
error: <user expression 28>:1:1: 'uxtb' has unknown type; cast it to its declared type to use it
uxtb.w
^~~~
I call (will want a short ) result = getCheckSum(A, B); from my java code.
The method in my C++ code is
//---------------------------------------------------------------------------
unsigned short ekmCheckCRC16(const unsigned char *dat, unsigned short len)
{
unsigned short crc = 0xffff;
while (len--)
{
crc = (crc >> 8 ) ^ ekmCrcLut[(crc ^ *dat++) & 0xff];
}
crc = (crc << 8 ) | (crc >> 8);
crc &= 0x7f7f;
return crc;
}
//---------------------------------------------------------------------------
// Implementation of the native method getCheckSum()
extern "C"
JNIEXPORT unsigned short JNICALL
Java_com_(...)_getCheckSum(JNIEnv *env, jobject thiz, jstring a) {
const char * aCStr = env->GetStringUTFChars(a, NULL);
if(NULL == aCStr)
return NULL;
unsigned short crc = ekmCheckCRC16(reinterpret_cast<const unsigned char *>(aCStr), strlen(aCStr));
return crc;
}
This code is experimental showing the actual code I want to run ekmCheckCRC16( ... ), its purpose is to learn how to return a value back to the java module.
The error message seems to be clear 'unknown' type cast, so question is, how should I be returning the value of aCStr?
Thanks in advance.
Solved my problem, was simple error of not changing one important detail before executing call i was looking for a return type of short but had String in native declaration.
I had
private native String getCheckSum(String a);
it should have been
`private native short getCheckSum(String a);`
My call was / is
short result = getCheckSum(A);
Worked fine after correcting my mistake.
for those interested my c++ code
#include <jni.h> // JNI header provided by JDK
#include "ekmCheckSum.h"
#include <iostream> // C++ standard IO header
using namespace std;
//---------------------------------------------------------------------------
void ekmCheckSum() {
}
static const unsigned short ekmCrcLut[256] = {
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
};
//---------------------------------------------------------------------------
unsigned short ekmCheckCRC16(const unsigned char *dat, unsigned short len)
{
unsigned short crc = 0xffff;
while (len--)
{
crc = (crc >> 8 ) ^ ekmCrcLut[(crc ^ *dat++) & 0xff];
}
crc = (crc << 8 ) | (crc >> 8);
crc &= 0x7f7f;
return crc;
}
//---------------------------------------------------------------------------
// Implementation of the native method getCheckSum()
extern "C"
JNIEXPORT unsigned short JNICALL
Java_com_[project name]_ekmV4Fields_getCheckSum(JNIEnv *env, jobject thiz, jstring a) {
const char * aCStr = env->GetStringUTFChars(a, NULL);
if(NULL == aCStr)
return NULL;
unsigned short crc = ekmCheckCRC16(reinterpret_cast<const unsigned char *>(aCStr), strlen(aCStr));
return crc;
}
my .h file contains
#ifndef PROJECT_NAME_EKMCHECKSUM_H
#define PROJECT_NAME_EKMCHECKSUM_H
class ekmCheckSum
{
private:
public:
ekmCheckSum();
unsigned short ekmCheckCRC16(const unsigned char *dat, unsigned short len);
};
#endif //PROJECT_NAME_EKMCHECKSUM_H
my java file includes
static {System.loadLibrary("ekmCheckSum");}
private native short getCheckSum(String a);
public void SetEkmFieldValueStrings(String A, String B)
{
/* if length of A is less than 250 chars, read is no good, discard
* NOTE: both Strings A and B will need to be validated for checksum
* TODO check A & B if checksum is correct
* */
boolean _aOk = false, _bOk=false;
short result = getCheckSum(A);
...
...
I've tried creating a simple jni test app from "Beginning Android Games 3rd Ed" book. I copy-pasted the code, but when I try to link with ndk-build, I get the following error messages:
D:\apps\android\projects\NDK\app\src\main\java>ndk-build
[armeabi-v7a] Compile++ arm : jniutils <= jniutils.cpp
jni/jniutils.cpp:8:52: error: format string is not a string literal (potentially insecure)
[-Werror,-Wformat-security]
__android_log_print(ANDROID_LOG_VERBOSE, cTag, cMessage);
^~~~~~~~
jni/jniutils.cpp:8:52: note: treat the string as an argument to avoid this
__android_log_print(ANDROID_LOG_VERBOSE, cTag, cMessage);
^
"%s",
1 error generated.
make: *** [obj/local/armeabi-v7a/objs/jniutils/jniutils.o] Error 1
If I try to treat these errors as warnings and suppress these with the following lines in android.mk / application.mk:
APP_CFLAGS += -Wno-error=format-security
LOCAL_DISABLE_FORMAT_STRING_CHECKS := true
Then I get this error:
D:\apps\android\projects\NDK\app\src\main\java>ndk-build
[armeabi-v7a] SharedLibrary : libjniutils.so
clang++.exe: error: no such file or directory: '遶上・llog'
make: *** [obj/local/armeabi-v7a/libjniutils.so] Error 1
Which I guess is just some garbage from memory, like a string /variable hasn't been addressed correctly.
I'm very new to jni, so I'm at a bit of a loss of how to troubleshoot this.
Code follows:
JniUtils.java
package com.badlogic.androidgames.ndk;
import java.nio.ByteBuffer;
public class JniUtils {
static {
System.loadLibrary("jniutils");
}
public static native void log(String tag, String message);
public static native void copy(ByteBuffer dst, float[] src, int offset, int len);
}
jniutils.cpp
#include <android/log.h>
#include <string.h>
#include "jniutils.h"
JNIEXPORT void JNICALL Java_com_badlogic_androidgames_ndk_JniUtils_log
(JNIEnv *env, jclass clazz, jstring tag, jstring message) {
const char *cTag = env-> GetStringUTFChars(tag, 0);
const char *cMessage = env-> GetStringUTFChars(message, 0);
__android_log_print(ANDROID_LOG_VERBOSE, cTag, cMessage);
env-> ReleaseStringUTFChars(tag, cTag);
env-> ReleaseStringUTFChars(message, cMessage);
}
JNIEXPORT void JNICALL Java_com_badlogic_androidgames_ndk_JniUtils_copy
(JNIEnv *env, jclass clazz, jobject dst, jfloatArray src, jint offset, jint len) {
unsigned char* pDst = (unsigned char*)env-> GetDirectBufferAddress(dst);
float* pSrc = (float*)env-> GetPrimitiveArrayCritical(src, 0); memcpy(pDst,
pSrc + offset, len * 4);
env-> ReleasePrimitiveArrayCritical(src, pSrc, 0);
}
application.mk
APP_ABI := armeabi-v7a x86
APP_PLATFORM := android-19
android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := jniutils
LOCAL_LDLIBS := − llog
LOCAL_ARM_MODE := arm
LOCAL_SRC_FILES := jniutils.cpp
include $(BUILD_SHARED_LIBRARY)
I have a c++ dll library with header files provided, without implementation.
And I implement JNA call for this library functions.
And I have the problem with only 1 function (other, even similar works fine). This is declaration from .h file:
int CALLINGCONV SMIMESignML(
const char* pin,
unsigned long slot,
const char* szOutputFilePath,
const char* szFrom,
const char* szTo,
const char* szSubject,
const char* szOtherHeaders,
const char* szBody,
const char* szAttachments,
unsigned long dwFlags,
int bInitialize
);
Java code:
public interface Dll extends StdCallLibrary {
public String JNA_LIBRARY_NAME = "libname.dll";
int SMIMESignML(String pPin, int slot, String pOut, String pFrom, String pTo,
String pSubject, String pHeaders, String pBody, String pAttachments, int flags,
int init);
}
public class Test {
private static final Dll dll = (Dll) Native.loadLibrary(Dll.JNA_LIBRARY_NAME, Dll.class, W32APIOptions.ASCII_OPTIONS);
public static void main(String[] args) {
String pOut = "";
String pFrom = "";
String pTo = "";
String pBody = "";
String pAttachments = "";
int code = dll.SMIMESignML(null, 0, pOut, pFrom, pTo, null, null, pBody, pAttachments, 0, 0);
System.out.println(code);
}
}
The function should return different int error codes, but it always return code 0xFFFF.
I can check it with the same code in Pascal:
unit dll;
interface
const
JNA_LIBRARY_NAME = 'libname.dll';
function SMIMESignML(pPin: PChar; slot: integer; pOut: PChar; pFrom: PChar; pTo: PChar;
pSubject: PChar; pHeaders: PChar; pBody: PChar; pAttachments: PChar; flags: integer;
init: integer): integer; stdcall; external JNA_LIBRARY_NAME;
implementation
end.
program Hello;
uses dll;
var
code: integer;
begin
code := SMIMESignML(nil, 0, '', '', '', nil, nil, '' , '', 0, 0);
writeln(code);
end.
Pascal code returns 2, Java code return 65535. Moreover, Pascal std calls work right, changing arguments we get different error codes (0=OK and others), but Java with the same arguments is not working, it always returns 0xFFFF.
How can I debug it to understand the problem?
P.S.
Moreover, in the same library I has this function and it works from JNA without any problems:
int CALLINGCONV PKCS7SignML(
const char *pin,
unsigned long slot,
const char* szInputFileName,
const char* szOutputFileName,
int bInitialize);
The OS is Win8 x64, JavaOracle7x86, library is x32.
"unsigned long" should not be the problem, as it should be 4 bytes on windows.
What am I doing wrong, if the same STD call returns different results in this two examples? And How can I debug it?
I had a problem executing a c method from java (jni) .
The content of the CMakeLists.txt is the follow :
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/home/runix/instalers/stasm4.1.0")
set(STASM_DIR ..)
find_package(OpenCV REQUIRED)
if(OpenCV_FOUND)
include_directories(${OpenCV_INCLUDE_DIRS})
endif()
find_package(STASM REQUIRED)
if(STASM_FOUND)
include_directories(${STASM_INCLUDE_DIRS})
endif()
find_package(JNI)
if(JNI_FOUND)
include_directories(${JNI_INCLUDE_DIRS})
endif()
LINK_DIRECTORIES( ${OpenCV_LIB_DIR} ${STASM_LINK_DIRS} ${JNI_LINK_DIRS})
SET(LIBS ${STASM_LIBRARIES} ${OpenCV_LIBS} ${JNI_LIBS})
set(CMAKE_CXX_FLAGS "${CMAKE_XX_FLAGS} -fPIC ")
SET(EXECUTABLES minimal)
FOREACH(var ${EXECUTABLES})
add_executable(${var} ${var}.cpp)
target_link_libraries(${var} ${LIBS})
ADD_LIBRARY(ctest SHARED ${var} ${var}.cpp)
ENDFOREACH(var)
The code compile and I can execute the executable correctly ( As you can see in the CMakeLists I generate the dynamic library and a executable )
But when I try to execute the code from java it throws an exception :
java -Djava.library.path=. StasmJNI
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/runix/instalers/stasm4.1.0/external/libctest.so: /home/runix/instalers/stasm4.1.0/external/libctest.so: undefined symbol: _ZTVN2cv11_InputArrayE
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1778)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1703)
at java.lang.Runtime.loadLibrary0(Runtime.java:844)
at java.lang.System.loadLibrary(System.java:1051)
at StasmJNI.<clinit>(StasmJNI.java:3)
If I remove all code from the c function java works correctly and I don't know what its the problem.
Java code :
public class StasmJNI {
static {
System.loadLibrary("ctest"); /* (2) */
}
public StasmJNI() {
}
public native float[] getPoints(String path);
public static void main(String[] args) {
System.out.println(new StasmJNI().getPoints("Prueba").length);
}
}
c code :
StasmJNI.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class StasmJNI */
#ifndef _Included_StasmJNI
#define _Included_StasmJNI
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: StasmJNI
* Method: getPoints
* Signature: (Ljava/lang/String;)[F
*/
JNIEXPORT jfloatArray JNICALL Java_StasmJNI_getPoints
(JNIEnv *, jobject, jstring);
#ifdef __cplusplus
}
#endif
#endif
StasmJNI.cpp
#include <stdio.h>
#include <stdlib.h>
#include "opencv/highgui.h"
#include "stasm_lib.h"
#include "StasmJNI.h"
void error(const char* s1, const char* s2)
{
printf("Stasm version %s: %s %s\n", stasm_VERSION, s1, s2);
exit(1);
}
using namespace cv;
float* getLandmarks(char * const path, int * size) {
if (!stasm_init("../data", 0 ))
error("stasm_init failed: ", stasm_lasterr());
cv::Mat_<unsigned char> img(cv::imread(path, CV_LOAD_IMAGE_GRAYSCALE));
if (!img.data)
error("Cannot load", path);
if (!stasm_open_image((const char*)img.data, img.cols, img.rows, path,
1 , 10 ))
error("stasm_open_image failed: ", stasm_lasterr());
int foundface;
float landmarks[2 * 20];// stasm_NLANDMARKS]; // x,y coords (note the 2)
int nfaces = 0;
int iters = 0;
while (iters++ < 2)
{
if (!stasm_search_auto(&foundface, landmarks))
error("stasm_search_auto failed: ", stasm_lasterr());
if (!foundface)
break; // note break
stasm_force_points_into_image(landmarks, img.cols, img.rows);
for (int i = 0; i < stasm_NLANDMARKS; i++)
img(cvRound(landmarks[i*2+1]), cvRound(landmarks[i*2])) = 255;
nfaces++;
}
if(nfaces == 1)
*size = stasm_NLANDMARKS * 2;
else
*size = 0;
return landmarks;
}
JNIEXPORT jfloatArray JNICALL Java_StasmJNI_getPoints
(JNIEnv * env, jobject object, jstring path) {
int size = 0;
getLandmarks(path2, &size);
jfloatArray result;
result = env->NewFloatArray(size);
return result;
}
int main()
{
int size = 0;
CvCapture *capture = cvCaptureFromCAM(0);
char* const path = "minimal2.jpg";
IplImage* ipl = cvQueryFrame(capture);
Mat temp = ipl;
cv::imwrite(path, temp);
getLandmarks(path, &size);
printf("the size %d\n", size);
}
(NOTE THE C++ CODE USE OPENCV AND STASM)
Thanks in advance :)
EDIT 1 : output of nm --demangle libctest.so
0000000000204210 d DW.ref.__gxx_personality_v0
00000000000026be T Java_StasmJNI_getPoints
0000000000203e08 a _DYNAMIC
0000000000203fe8 a _GLOBAL_OFFSET_TABLE_
w _Jv_RegisterClasses
U _Unwind_Resume##GCC_3.0
00000000000023cc T getLandmarks(char*, int*)
000000000000238c T error(char const*, char const*)
0000000000002845 W cvRound(double)
000000000000329c r stasm_NLANDMARKS
U cv::_InputArray::_InputArray(cv::Mat const&)
000000000000314c W cv::_InputArray::_InputArray<unsigned char>(cv::Mat_<unsigned char> const&)
000000000000314c W cv::_InputArray::_InputArray<unsigned char>(cv::Mat_<unsigned char> const&)
00000000000030c0 W cv::_OutputArray::_OutputArray<unsigned char>(cv::Mat_<unsigned char>&)
00000000000030c0 W cv::_OutputArray::_OutputArray<unsigned char>(cv::Mat_<unsigned char>&)
U cv::Mat::deallocate()
0000000000002bde W cv::Mat::MSize::MSize(int*)
0000000000002bde W cv::Mat::MSize::MSize(int*)
0000000000002bf8 W cv::Mat::MStep::MStep()
0000000000002bf8 W cv::Mat::MStep::MStep()
0000000000002c52 W cv::Mat::MStep::operator[](int)
0000000000002b10 W cv::Mat::release()
U cv::Mat::copySize(cv::Mat const&)
000000000000287a W cv::Mat::initEmpty()
U cv::Mat::Mat(_IplImage const*, bool)
000000000000290a W cv::Mat::Mat()
000000000000290a W cv::Mat::Mat()
0000000000002950 W cv::Mat::~Mat()
0000000000002950 W cv::Mat::~Mat()
0000000000002990 W cv::Mat::operator=(cv::Mat const&)
0000000000002d3a W cv::Mat_<unsigned char>::Mat_(cv::Mat const&)
0000000000002d3a W cv::Mat_<unsigned char>::Mat_(cv::Mat const&)
0000000000002ca2 W cv::Mat_<unsigned char>::~Mat_()
0000000000002ca2 W cv::Mat_<unsigned char>::~Mat_()
0000000000002eb8 W cv::Mat_<unsigned char>::operator=(cv::Mat const&)
0000000000002da2 W cv::Mat_<unsigned char>::operator()(int, int)
00000000000031a2 W cv::Size_<int>::Size_()
00000000000031a2 W cv::Size_<int>::Size_()
U cv::imread(std::string const&, int)
U cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)
U cv::fastFree(void*)
0000000000002c74 W JNIEnv_::NewFloatArray(int)
000000000000311c W __gnu_cxx::new_allocator<int>::deallocate(int*, unsigned long)
0000000000003198 W __gnu_cxx::new_allocator<int>::new_allocator()
0000000000003198 W __gnu_cxx::new_allocator<int>::new_allocator()
0000000000003112 W __gnu_cxx::new_allocator<int>::~new_allocator()
0000000000003112 W __gnu_cxx::new_allocator<int>::~new_allocator()
0000000000002bb4 W cv::Mat::type() const
0000000000002c30 W cv::Mat::MStep::operator[](int) const
0000000000002bca W cv::Mat::depth() const
U cv::Mat::reshape(int, int, int const*) const
U cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const
00000000000030b0 W cv::Mat_<unsigned char>::type() const
U std::allocator<char>::allocator()##GLIBCXX_3.4
U std::allocator<char>::~allocator()##GLIBCXX_3.4
00000000000030f8 W std::allocator<int>::allocator()
00000000000030f8 W std::allocator<int>::allocator()
000000000000303c W std::allocator<int>::~allocator()
000000000000303c W std::allocator<int>::~allocator()
U std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)##GLIBCXX_3.4
U std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()##GLIBCXX_3.4
000000000000313e W void std::_Destroy_aux<true>::__destroy<int*>(int*, int*)
0000000000002ffe W std::_Vector_base<int, std::allocator<int> >::_Vector_impl::_Vector_impl()
0000000000002ffe W std::_Vector_base<int, std::allocator<int> >::_Vector_impl::_Vector_impl()
0000000000002dda W std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()
0000000000002dda W std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()
0000000000003056 W std::_Vector_base<int, std::allocator<int> >::_M_deallocate(int*, unsigned long)
0000000000002e80 W std::_Vector_base<int, std::allocator<int> >::_M_get_Tp_allocator()
0000000000002df4 W std::_Vector_base<int, std::allocator<int> >::_Vector_base()
0000000000002df4 W std::_Vector_base<int, std::allocator<int> >::_Vector_base()
0000000000002e0e W std::_Vector_base<int, std::allocator<int> >::~_Vector_base()
0000000000002e0e W std::_Vector_base<int, std::allocator<int> >::~_Vector_base()
0000000000002cbc W std::vector<int, std::allocator<int> >::vector()
0000000000002cbc W std::vector<int, std::allocator<int> >::vector()
0000000000002cd6 W std::vector<int, std::allocator<int> >::~vector()
0000000000002cd6 W std::vector<int, std::allocator<int> >::~vector()
000000000000308a W void std::_Destroy<int*>(int*, int*)
0000000000002e8e W void std::_Destroy<int*, int>(int*, int*, std::allocator<int>&)
U vtable for cv::_InputArray
U vtable for cv::_OutputArray
0000000000203e00 d __gthread_active_p()::__gthread_active_ptr
U operator delete(void*)##GLIBCXX_3.4
0000000000203de0 d __CTOR_END__
0000000000203dd8 d __CTOR_LIST__
0000000000203df0 d __DTOR_END__
0000000000203de8 d __DTOR_LIST__
00000000000039b8 r __FRAME_END__
0000000000203df8 d __JCR_END__
0000000000203df8 d __JCR_LIST__
0000000000204218 A __bss_start
w __cxa_finalize##GLIBC_2.2.5
00000000000031d0 t __do_global_ctors_aux
00000000000022e0 t __do_global_dtors_aux
0000000000204208 d __dso_handle
w __gmon_start__
U __gxx_personality_v0##CXXABI_1.3
0000000000204218 A _edata
0000000000204228 A _end
0000000000003208 T _fini
0000000000001e80 T _init
00000000000022c0 t call_gmon_start
0000000000204218 b completed.6531
U cvCreateCameraCapture
U cvQueryFrame
0000000000204220 b dtor_idx.6533
U exit##GLIBC_2.2.5
0000000000002360 t frame_dummy
U printf##GLIBC_2.2.5
w pthread_cancel
U stasm_VERSION
U stasm_force_points_into_image
U stasm_init
U stasm_lasterr
U stasm_open_image
U stasm_search_auto
Edit 2 : output of ldd
linux-vdso.so.1 => (0x00007fff693fe000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fd2a639d000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fd2a609d000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd2a5da0000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd2a5b83000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fd2a597b000)
libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007fd2a572a000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007fd2a5502000)
libtiff.so.4 => /usr/lib/x86_64-linux-gnu/libtiff.so.4 (0x00007fd2a529e000)
libjasper.so.1 => /usr/lib/x86_64-linux-gnu/libjasper.so.1 (0x00007fd2a5046000)
libv4l1.so.0 => /usr/lib/x86_64-linux-gnu/libv4l1.so.0 (0x00007fd2a4e40000)
libavcodec.so.53 => /usr/lib/x86_64-linux-gnu/libavcodec.so.53 (0x00007fd2a402f000)
libavformat.so.53 => /usr/lib/x86_64-linux-gnu/libavformat.so.53 (0x00007fd2a3d2e000)
libavutil.so.51 => /usr/lib/x86_64-linux-gnu/libavutil.so.51 (0x00007fd2a3b0e000)
libswscale.so.2 => /usr/lib/x86_64-linux-gnu/libswscale.so.2 (0x00007fd2a38c8000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fd2a36b1000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd2a32f1000)
libv4l2.so.0 => /usr/lib/x86_64-linux-gnu/libv4l2.so.0 (0x00007fd2a30e5000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd2a65d5000)
libvpx.so.1 => /usr/lib/libvpx.so.1 (0x00007fd2a2e3f000)
libvorbisenc.so.2 => /usr/lib/x86_64-linux-gnu/libvorbisenc.so.2 (0x00007fd2a2970000)
libvorbis.so.0 => /usr/lib/x86_64-linux-gnu/libvorbis.so.0 (0x00007fd2a2744000)
libtheoraenc.so.1 => /usr/lib/x86_64-linux-gnu/libtheoraenc.so.1 (0x00007fd2a2506000)
libtheoradec.so.1 => /usr/lib/x86_64-linux-gnu/libtheoradec.so.1 (0x00007fd2a22eb000)
libspeex.so.1 => /usr/lib/x86_64-linux-gnu/libspeex.so.1 (0x00007fd2a20d2000)
libschroedinger-1.0.so.0 => /usr/lib/libschroedinger-1.0.so.0 (0x00007fd2a1e1e000)
libgsm.so.1 => /usr/lib/libgsm.so.1 (0x00007fd2a1c10000)
libva.so.1 => /usr/lib/x86_64-linux-gnu/libva.so.1 (0x00007fd2a19fa000)
libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007fd2a17e9000)
libv4lconvert.so.0 => /usr/lib/x86_64-linux-gnu/libv4lconvert.so.0 (0x00007fd2a1574000)
libogg.so.0 => /usr/lib/x86_64-linux-gnu/libogg.so.0 (0x00007fd2a136c000)
liborc-0.4.so.0 => /usr/lib/x86_64-linux-gnu/liborc-0.4.so.0 (0x00007fd2a10f1000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd2a0eed000)
EDIT 3:
I load the output of ldd but the program crash again when load ctest library
with undefined symbol: _ZTVN2cv11_InputArrayE.
System.load("/lib/x86_64-linux-gnu/libz.so.1");
System.load("/usr/lib/x86_64-linux-gnu/libstdc++.so.6");
System.load("/lib/x86_64-linux-gnu/libpthread.so.0");
System.load("/lib/x86_64-linux-gnu/librt.so.1");
System.load("/usr/lib/x86_64-linux-gnu/libjpeg.so.8");
System.load("/lib/x86_64-linux-gnu/libpng12.so.0");
System.load("/usr/lib/x86_64-linux-gnu/libtiff.so.4");
System.load("/usr/lib/x86_64-linux-gnu/libjasper.so.1");
System.load("/usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0");
System.load("/usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0");
System.load("/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0");
System.load("/lib/x86_64-linux-gnu/libglib-2.0.so.0");
System.load("/lib/x86_64-linux-gnu/libm.so.6");
System.load("/lib/x86_64-linux-gnu/libgcc_s.so.1");
System.load("/lib/x86_64-linux-gnu/libc.so.6");
System.load("/lib64/ld-linux-x86-64.so.2");
System.load("/usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0");
System.load("/usr/lib/x86_64-linux-gnu/libX11.so.6");
System.load("/usr/lib/x86_64-linux-gnu/libXfixes.so.3");
System.load("/usr/lib/x86_64-linux-gnu/libatk-1.0.so.0");
System.load("/usr/lib/x86_64-linux-gnu/libcairo.so.2");
System.load("/usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0");
System.load("/usr/lib/x86_64-linux-gnu/libgio-2.0.so.0");
System.load("/usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0");
System.load("/usr/lib/x86_64-linux-gnu/libpango-1.0.so.0");
System.load("/usr/lib/x86_64-linux-gnu/libfontconfig.so.1");
System.load("/usr/lib/x86_64-linux-gnu/libXext.so.6");
System.load("/usr/lib/x86_64-linux-gnu/libXrender.so.1");
System.load("/usr/lib/x86_64-linux-gnu/libXinerama.so.1");
System.load("/usr/lib/x86_64-linux-gnu/libXi.so.6");
System.load("/usr/lib/x86_64-linux-gnu/libXrandr.so.2");
System.load("/usr/lib/x86_64-linux-gnu/libXcursor.so.1");
System.load("/usr/lib/x86_64-linux-gnu/libXcomposite.so.1");
System.load("/usr/lib/x86_64-linux-gnu/libXdamage.so.1");
System.load("/usr/lib/x86_64-linux-gnu/libffi.so.6");
System.load("/lib/x86_64-linux-gnu/libpcre.so.3");
System.load("/usr/lib/x86_64-linux-gnu/libfreetype.so.6");
System.load("/usr/lib/x86_64-linux-gnu/libxcb.so.1");
System.load("/lib/x86_64-linux-gnu/libdl.so.2");
System.load("/usr/lib/x86_64-linux-gnu/libpixman-1.so.0");
System.load("/usr/lib/x86_64-linux-gnu/libxcb-shm.so.0");
System.load("/usr/lib/x86_64-linux-gnu/libxcb-render.so.0");
System.load("/usr/lib/x86_64-linux-gnu/libgmodule-2.0.so.0");
System.load("/lib/x86_64-linux-gnu/libselinux.so.1");
System.load("/lib/x86_64-linux-gnu/libresolv.so.2");
System.load("/lib/x86_64-linux-gnu/libexpat.so.1");
System.load("/usr/lib/x86_64-linux-gnu/libXau.so.6");
System.load("/usr/lib/x86_64-linux-gnu/libXdmcp.so.6");
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
//Program crash here
System.loadLibrary("ctest");
SOLVED : Here is my solution,
Compile first into static library ( CMakeLists.txt)
find_package(OpenCV REQUIRED)
if(OpenCV_FOUND)
include_directories(${OpenCV_INCLUDE_DIRS})
endif()
LINK_DIRECTORIES(
${OpenCV_LIB_DIR}
)
SET(STASM_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
SET(OBJ_STASM
${STASM_BASE_DIR}/stasm/asm.cpp
${STASM_BASE_DIR}/stasm/classicdesc.cpp
${STASM_BASE_DIR}/stasm/convshape.cpp
${STASM_BASE_DIR}/stasm/err.cpp
${STASM_BASE_DIR}/stasm/eyedet.cpp
${STASM_BASE_DIR}/stasm/eyedist.cpp
${STASM_BASE_DIR}/stasm/faceroi.cpp
${STASM_BASE_DIR}/stasm/hat.cpp
${STASM_BASE_DIR}/stasm/hatdesc.cpp
${STASM_BASE_DIR}/stasm/landmarks.cpp
${STASM_BASE_DIR}/stasm/misc.cpp
${STASM_BASE_DIR}/stasm/pinstart.cpp
${STASM_BASE_DIR}/stasm/print.cpp
${STASM_BASE_DIR}/stasm/shape17.cpp
${STASM_BASE_DIR}/stasm/shapehacks.cpp
${STASM_BASE_DIR}/stasm/shapemod.cpp
${STASM_BASE_DIR}/stasm/startshape.cpp
${STASM_BASE_DIR}/stasm/stasm.cpp
${STASM_BASE_DIR}/stasm/stasm_lib.cpp
)
SET(OBJ_MOD1
${STASM_BASE_DIR}/stasm/MOD_1/facedet.cpp
${STASM_BASE_DIR}/stasm/MOD_1/initasm.cpp
)
include_directories(${STASM_BASE_DIR}/stasm)
include_directories(${STASM_BASE_DIR}/stasm/MOD_1)
SET(STASM_INCLUDE_DIRS
${STASM_BASE_DIR}/stasm
${STASM_BASE_DIR}/stasm/MOD_1
)
SET(LIBS ${OpenCV_LIBS})
set(CMAKE_CXX_FLAGS "${CMAKE_XX_FLAGS} -fPIC ")
set(STASM_LIBS stasm)
add_library(${STASM_LIBS} ${OBJ_MOD1} ${OBJ_STASM})
target_link_libraries(${STASM_LIBS} ${LIBS})
SET(EXECUTABLES minimal minimal2)
FOREACH(var ${EXECUTABLES})
add_executable(${var} apps/${var}.cpp)
target_link_libraries(${var} ${STASM_LIBS} ${LIBS})
ENDFOREACH(var)
#**************************************************************************************************
# Generate batch files for examples
#**************************************************************************************************
#setup Config.cmake
configure_file(STASMConfig.cmake.in
"${PROJECT_BINARY_DIR}/STASMConfig.cmake" #ONLY)
INSTALL(
FILES ${PROJECT_BINARY_DIR}/STASMConfig.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/
COMPONENT dev)
Extract static library from .a
ar -x static_library_name
Compile to a shared library
gcc -shared -o libctest2.so minimal.cpp.o -Wl,-rpath, /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so $PWD/libstasm.so
Thanks for https://stackoverflow.com/users/1823225/graham-griffiths user!
A quick google search for _ZTVN2cv11_InputArrayE shows that it should be part of library libopencv_core.so - you will have to make sure this is loaded in Java before calling your JNI function.
So, add this line below and make sure the library is available somewhere Java can find it :
System.loadLibrary("opencv_core");
EDIT : by the way you can see the references to _InputArray in your output from nm, with a U for undefined (if you run it without the --demangle option, it will print the 'mangled' name which will exactly match the undefined symbol it complains about). What this means - your code refers to some opencv types / functions - the symbols are left undefined in your library file, so to run properly it needs the opencv library file to be loaded too.
You'll probably need to do the same thing with your stasm library too.