java-native-interface

Calling C++ from Java, but Java loads the wrong Glibc version

◇◆丶佛笑我妖孽 提交于 2020-01-04 23:01:12
问题 I am trying to call a C++ library from java side and have written necessary jni code. However, when my java code tries to load my C++ library via System.loadLibrary , it complains the following error: Exception in thread "main" java.lang.UnsatisfiedLinkError: libmylib.so: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by libmylib.so) I later found that it is because I have two different GLIBC versions on my system, and the default one is the older one, while libmylib

Display C++ program in Java

陌路散爱 提交于 2020-01-04 15:32:07
问题 I'm new to JNI and just started learning it. I have successfully executed a graphical C++ program in java using JNI . Now i want to try something more advanced which is display that C++ graphical program within JFrame or JPanel. Is it possible and how to do it ? Ideally it would be something like this Thanks for answering and sorry if my question is vague. Edit : This is quite similiar to my question Display a C++ window in a java GUI 回答1: Theoretically that should be possible, although not

How to Get the values of method local variables and class variables using jvmti

本秂侑毒 提交于 2020-01-04 13:48:40
问题 I am trying to capture the variable values using JVMTI, when an exception event is generated, i went through the jvmti documentation and found that there are no functions which let me retrieve the values of the fields(variables), how can this be achieved ? Below is the Agent code: #include<jni.h> #include<jvmti.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> typedef struct { jvmtiEnv *jvmti; jrawMonitorID lock; } GlobalAgentData; static GlobalAgentData *gdata; static bool check

Android NDK: Warning: There are no modules to build in this project

巧了我就是萌 提交于 2020-01-04 13:27:45
问题 I'm new in NDK development and I'm currently facing a problem, when I try to invoke the ndk build tool from cygwin terminal: Android NDK: WARNING: There are no modules to build in this project! I’m under windows (x64) and I use the r10d (64-bit) NDK. I try to invoke it from the root of my project that contains a jni folder with a simple .c file and an Android.mk: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # Here we give our module name and source file(s) LOCAL_MODULE := mycfile LOCAL

How to solve “fatal: relocations remain against allocatable but non-writable sections” while using Java native interface?

為{幸葍}努か 提交于 2020-01-04 12:48:31
问题 I'm trying to call a C function inside a Java code. I have this hava code. public class JavaToC { public native void helloC(); static { System.loadLibrary("HelloWorld"); } public static void main(String[] args) { new JavaToC().helloC(); } } . I compiled it and then created header file. Then make the following HelloWorld.c file. #include <stdio.h> #include <jni.h> #include "JavaToC.h" JNIEXPORT void JNICALL Java_JavaToC_helloC(JNIEnv *env, jobject javaobj) { printf("Hello World: From C");

How to solve “fatal: relocations remain against allocatable but non-writable sections” while using Java native interface?

眉间皱痕 提交于 2020-01-04 12:47:11
问题 I'm trying to call a C function inside a Java code. I have this hava code. public class JavaToC { public native void helloC(); static { System.loadLibrary("HelloWorld"); } public static void main(String[] args) { new JavaToC().helloC(); } } . I compiled it and then created header file. Then make the following HelloWorld.c file. #include <stdio.h> #include <jni.h> #include "JavaToC.h" JNIEXPORT void JNICALL Java_JavaToC_helloC(JNIEnv *env, jobject javaobj) { printf("Hello World: From C");

Changing package name android manifest causes problems JNI

送分小仙女□ 提交于 2020-01-04 09:07:53
问题 I have been modifying and playing around with this project: source code : https://bitbucket.org/viet0904163136/gba-android/src It's a gameboy advance emulator licensed under GPLv2. Every thing works ok until i change the packagename in the android manifest file. Without the package name changed the app works without a problem. But when the package name is changed the SDLactivity quits with this message: (i renamed it to com.gba.emu) 09-01 12:23:16.409: I/SDL(884): SDL_Android_Init() 09-01 12

Debugging Android JNI/C++ No Debug Symbols Found Target Machine Actively Refused Connection

爱⌒轻易说出口 提交于 2020-01-04 08:27:52
问题 Here is the console log: (no debugging symbols found) D:\ws\test\MyProject\obj\local\armeabi\gdb2.setup:4: Error in sourced command file: :5039: No connection could be made because the target machine actively refused it. localhost:5039: No connection could be made because the target machine actively refused it. Following debug steps for eclipse plugin sequoyah: http://www.eclipse.org/sequoyah/documentation/native_debug.php I'm almost at the end trying to connect the C++ Debugging. My Android

Clarification about GetFieldID

我的未来我决定 提交于 2020-01-04 06:33:16
问题 I was trying to build a native method and although it seems to run fine, but I am struggling to understand a field [*sig] in a function - jfieldID GetFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig); https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html For example I have a small Java code, which uses an instance variable called "i" and all this native method(named test) does is multiply this by 2. Now I am referring to Java Complete Reference

JNI_CreateJavaVM crash my program without any message or exception

纵饮孤独 提交于 2020-01-04 04:39:09
问题 Recently I begin to use JNI in my project. Here is my code: options[0].optionString = "-Djava.class.path=."; memset(&vm_args, 0, sizeof(vm_args)); vm_args.version = JNI_VERSION_1_2; vm_args.nOptions = 1; vm_args.options = options; vm_args.ignoreUnrecognized = JNI_TRUE; status = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); It crashes in JNI_CreateJavaVM() and my program aborts without any message or exception. Visual Studio gives me: 'SurvivorCore.exe': Loaded 'D:\Develop\Survivor\x86\Debug