how to fix fatal error jvmti.h No such file or directory compilation terminated c code ubuntu?

StackOverflow https://stackoverflow.com/questions/19587473

  •  01-07-2022
  •  | 
  •  

Question

how to fix fatal error jvmti.h No such file or directory compilation terminated c code ubuntu? my c code is:

include "jvmti.h"

JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {

/* We return JNI_OK to signify success */ printf("\nmy name is,\n\n");

return JNI_OK;

}

JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm) { }

type this command in terminal: gcc -Wall -W -Werror first_agent.c -o firstagent

first_agent.c:1:19: fatal error: jvmti.h: No such file or directory compilation terminated.

where java jdk version javac 1.7.0_25

where gcc version gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-2ubuntu4)

here should update gcc version to 4.8?

No correct solution

OTHER TIPS

This question is now pretty old, but probably someone will stumble across this in the future.

As @Gyro Gearless already mentioned, you need to specify the "Include directories".

For Java 8 on Ubuntu 15.04 I found the folders at

  • /usr/lib/jvm/java-1.8.0-openjdk-amd64/include
  • /usr/lib/jvm/java-1.8.0-openjdk-amd64/include/linux

In this directories you can find the following header files:

  • classfile_constants.h
  • jawt.h
  • jdwpTransport.h
  • jni.h
  • jvmticmlr.h
  • jvmti.h

which are needed by the compiler to include.

If you are using Netbeans you can add those include directory via the properties of your project: Right-click on you Project and select

You need to tell gcc where it can find its include files using -I option. Here is a sample invocation for building a JNI library. Note this was automatically created from some Maven plugin on Windows, so it is a bit noisy:

g++ -m64 -shared -IC:\work\Produktiv\jdpapi\jdpapi-native\src\main\native 
 -IC:\work\Produktiv\jdpapi\jdpapi-native\target\native\javah 
 -IC:\opt\Java\jdk1.7.0_40\jre\..\include 
 -IC:\opt\Java\jdk1.7.0_40\jre\..\include\win32 
 -o C:\work\Produktiv\jdpapi\jdpapi-native\target\objs\DPAPI.obj 
 -c C:\work\Produktiv\jdpapi\jdpapi-native\src\main\native\DPAPI.cpp

Note this is really just one line; and of course you have to adjust the paths for Linux :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top