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

2

5

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?

Berners answered 25/10, 2013 at 10:33 Comment(0)
D
5

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 "Properties"

Deposition answered 18/11, 2015 at 9:7 Comment(0)
D
2

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 :-)

Delvecchio answered 25/10, 2013 at 10:53 Comment(2)
thanks Gyro Gearless but i don't understand... iam using ubuntu 13.04 not windows...Berners
gcc behaves similar on Linux and Windows. Unfortunately, i have no Linux box in reach, but maybe you may find some better examples here: #3951135Delvecchio

© 2022 - 2024 — McMap. All rights reserved.