1

My goal is to complete the beginning netbeans java / c JNIDemo application that can be found at the website https://netbeans.apache.org/kb/docs/cnd/beginning-jni-linux.html

I have completed the majority of the steps to do this however I am stuck at the "Implementing a Method" step. The code for this method of the JNIDemoCld.c file follows.

The following image shows the yellow warning lightbulb on line 1

enter image description here

When hovering over the lightbulb the following message appears which I have tried and tried to google and troubleshoot without success, it appears that the source of this warning is the jni.h file.

"Library File /usr/lib/jvm/java-1.8.0-openjdk-amd64/include/jni.h

but there is an unresolved #include <sys/cdefs.h>

in included /user/include/features.h"

The build failed message is rather lengthy.

cd '/home/jerryw/NetBeansProjects/JNIDemoCdl'
/usr/bin/gmake -f Makefile CONF=Debug
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= 

SUBPROJECTS= .build-conf
    gmake[1]: Entering directory '/home/jerryw/NetBeansProjects/JNIDemoCdl'

"/usr/bin/gmake"  -f nbproject/Makefile-Debug.mk dist/libJNIDemoCdl.so
gmake[2]: Entering directory '/home/jerryw/NetBeansProjects/JNIDemoCdl'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/JNIDemo.o.d"
gcc -shared -m32   -c -g -I/usr/lib/jvm/java-1.8.0-openjdk-amd64/include -I/usr/lib/jvm/java-1.8.0-openjdk-amd64/include/linux -include /usr/lib/jvm/java-1.8.0-openjdk-amd64/include/classfile_constants.h -include /usr/lib/jvm/java-1.8.0-openjdk-amd64/include/jni.h -include /usr/lib/jvm/java-1.8.0-openjdk-amd64/include/jvmti.h -include /usr/lib/jvm/java-1.8.0-openjdk-amd64/include/jvmticmlr.h -include /usr/lib/jvm/java-1.8.0-openjdk-amd64/include/linux/jni_md.h -fPIC  -MMD -MP -MF "build/Debug/GNU-Linux/JNIDemo.o.d" -o build/Debug/GNU-Linux/JNIDemo.o JNIDemo.c
In file included from /usr/lib/jvm/java-1.8.0-openjdk-amd64/include/jni.h:39,
                 from <command-line>:32:
/usr/include/stdio.h:27:10: fatal error: bits/libc-header-start.h: No such file or directory
   27 | #include <bits/libc-header-start.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [nbproject/Makefile-Debug.mk:68: build/Debug/GNU-Linux/JNIDemo.o] Error 1
gmake[2]: Leaving directory '/home/jerryw/NetBeansProjects/JNIDemoCdl'
gmake[1]: *** [nbproject/Makefile-Debug.mk:59: .build-conf] Error 2
gmake[1]: Leaving directory '/home/jerryw/NetBeansProjects/JNIDemoCdl'
gmake: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2

BUILD FAILED (exit value 2, total time: 74ms)

[3] No problem with running a trivial "Hello World" application.

Re:[2] Could you be a little more specific as to what I did setting up the C/C++ environment? My interpretation of this is that I added include headers and directories as the location of the include and include/linux directories.

However,Re:[4] as you said, because this is such an old tutorial, it probably won't work properly now anyway.

For example, here is the part where I think the problem started:

Setting Project Properties
Right-click the JNIDemoCdl project node and choose Properties.

In the Properties dialog box, select the C Compiler node under the Build properties.

***
Click the Include Directories and Headers …​ button and click Add in the Include Directories and Headers dialog box.

Browse into your JDK directory, and select the include subdirectory.

Select the Store path as Absolute option, then click Select to add this directory to the project’s Include Directories.

Add the JDK’s include/linux directory in the same way, then click OK.

There are two entries in the actual C compiler look in directories instead of one combined ...One line is for setting the Include directory and the next line is for Include Headers. I added all of the headers to the Include headers entry. This is only my guess as to the source of the failed build.

skomisa
  • 16,436
  • 7
  • 61
  • 102
  • 1
    [1] Re _"Don't want to just post the whole thing though."_, please post the whole thing! And in text form rather than as a screen shot. [2] Describe what you did to set up the required C/C++ environment. [3] Consider creating and running a trivial C/C++ _"Hello world!"_ application through the Project Wizard, just to verify that your C/C++ environment is working correctly. Use **File > New Project > C/C++ > Lightweight C/C++ project** to do that. [4] Although that JNI tutorial is posted for NetBeans 12.5, it is very old and simply might not be valid any more. – skomisa Nov 29 '21 at 03:38
  • 1
    [1] Never post additional information about your question as an answer. Copy that information to your question ASAP, since your answer is liable to be deleted at any time. [2] After you have copied the information, delete your answer. [3] Take a look at this SO question: ["fatal error: bits/libc-header-start.h: No such file or directory" while compiling HTK](https://stackoverflow.com/q/54082459/2985643). Although the problem is not a duplicate of yours,, the underlying error is identical, so perhaps the accepted answer will help you. – skomisa Nov 30 '21 at 20:46
  • skomisa, you were correct, the underlying error was identical to the one I was encountering. I resolved it by installing gcc multilib using apt-get install gcc-multilib package when using -m32, Now, I can finish the very old tutorial. If you have any suggestions on newer similar tutorials/projects to this one it would be greatly appreciate. Thanks! – Jerry Weinstein Dec 02 '21 at 05:58
  • [1] OK - good that it's resolved. Would you mind posting and accepting an answer to explain what you did? That's more helpful to the SO community than having resolution buried in the comments. [2] I replaced your [header] tag with a [java-native-interface] tag. [3] The two part video [Java Native Interface (JNI) in depth](https://www.youtube.com/watch?v=CwwFp4qhQyw) might be worth a look. It's not new, but using JNI doesn't really change much over time. [4] Unrelated, but note that when replying you should prefix the user ID with an `@` sign (e.g. *@skomisa* rather than *skomisa*). – skomisa Dec 02 '21 at 09:43

1 Answers1

1

@skomisa Thank you for your style tips. I appreciate it.

1Here is summary of the actions I took to resolve this initial failed

attempt to implement a method of a Java Native Interface project implementing

a a Dynamic C/C++ Library.

The failure of the build centered around the settings for:

Build->C Compiler ->Additional Options->-shared -m32

The compiler needed the include header of start.h header and it isn't in the

include library. I may have added the include libraries incorrectly due to

an inconsistency in the very old protocall and the version of NetBeans I have

installed for this project.

Thanks to @skomisa for providing the link :

"fatal error: bits/libc-header-start.h: No such file or directory" while compiling HTK

where I found the solution.

So I installed the gcc -multilib with "sudo apt-get install gcc multilib".

This added available header files for the additional options setting -m32

setting.

After that, the build was successful.