1

I have searched the entire web throughly for almost two days now and couldn't come up with a solution to my problem. I hope you guys can help me. This might be a little specific but I am sure sooner or later others will experience the same problems.

I am currently using NetBeans Dev (Build 201803200002) with Java JDK 9.0.4 on a Windows 10, 64-bit system.

I was working through this JNI tutorial: https://cnd.netbeans.org/docs/jni/beginning-jni-win.html

Almost at the end, below figure 13, you are supposed to build the project HelloWorldNative (in my case it is called JNITestNative).

But I always get the following error message:

cd 'D:\NetBeans\projects\JNITestNative'
C:\Programme\cygwin\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/d/NetBeans/projects/JNITestNative'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/JNITestNative.dll
make[2]: Entering directory '/cygdrive/d/NetBeans/projects/JNITestNative'
mkdir -p build/Debug/Cygwin-Windows
rm -f "build/Debug/Cygwin-Windows/JNITest.o.d"
gcc -mno-cygwin -Wl,--add-stdcall-alias shared -m32   -c -g -I/cygdrive/C/Program\ Files/Java/jdk-9.0.4/include -I/cygdrive/C/Program\ Files/Java/jdk-9.0.4/include/win32  -MMD -MP -MF "build/Debug/Cygwin-Windows/JNITest.o.d" -o build/Debug/Cygwin-Windows/JNITest.o JNITest.c
gcc: error: shared: No such file or directory
gcc: error: unrecognized command line option '-mno-cygwin'; did you mean '-mno-clwb'?
nbproject/Makefile-Debug.mk:66: recipe for target 'build/Debug/Cygwin-Windows/JNITest.o' failed
make[2]: *** [build/Debug/Cygwin-Windows/JNITest.o] Error 1
make[2]: Leaving directory '/cygdrive/d/NetBeans/projects/JNITestNative'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/d/NetBeans/projects/JNITestNative'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 1s)

NetBeans seems to be missing a file which I am expecting it to generate in the first place - JNITest.o

I checked the directories ...jdk-9.0.4/include, ...jdk9.0.4/include/win32 and ...Debug/Cygwin-Windows. All of them exist, but the files JNITest.o.d or JNITest.o do not.

I tried to replace "cygwin" by "clwb" as suggested in the second error message, but the first error still occurs.

According to some sources in the internet I also removed the whole part "-mno-cygwin" from the additional options but the first error still occurs.

According to some other sources in the internet I added my ...cygwin/bin directory to the include directories, but this did not improve anything.

I have absolutely no idea how to solve this or how to search for other potential solutions anymore.

I hope anyone here can help.

el platin
  • 11
  • 3
  • You're missing a `-` in front of `shared`, so gcc thinks it's an input file and not the option `-shared` (from the tutorial), closing as typo. – Jorn Vernee Apr 06 '18 at 13:14
  • Many thanks. This fixed the first error. Still no successfull build though. Should I open a new question or edit my initial post? – el platin Apr 09 '18 at 06:58
  • It's up to you I suppose. If the problem is similar enough I'd say you can edit, but the right thing to do is to post a new question. Looking at this again, you also have to drop the `-m32` flag, since that is for 32-bit builds, but it looks like you have a 64-bit VM. – Jorn Vernee Apr 09 '18 at 08:13

1 Answers1

0

The correct answer was stated by Jorn Vernee in his comment. A '-' was missing before the argument "shared". Thank you for that.

For anyone else who might be experiencing this problem, let me sum up how I got from here to a successful build.

According to this and this I added three code lines for the definition of data type __int64, so now my JNITest.c looks like this:

#ifdef __CYGWIN__
#define __int64 long long
#endif

#include <jni.h>
#include <stdio.h>
#include "JNITest.h"

JNIEXPORT void JNICALL Java_com_plaettner_jnitest_JNITest_nativePrint
    (JNIEnv *env, jobject obj)
{
    printf("\nHello World from C\n");
}

Next I added the packages "mingw64-i686-gcc-core: GCC for Win32" and "mingw64-i686-gcc-g++: GCC for Win32" to my Cygwin.

In NetBeans options - C/C++ - Build Tools I then changed the C and C++ Compiler from gcc/g++ to i686-w64-mingw32-gcc/g++ respectively.

In the project properties in the categories Build - C Compiler/C++ Compiler I changed the additional options from "-mno-cygwin -Wl,--add-stdcall-alias -shared -m32" to "-Wl,--add-stdcall-alias -shared" and added my ...cygwin/bin directory to the include directories.

This leads to a successful build already. Anyway I added "-m32" to the additional options again and changed c/c++ Compiler back to gcc/g++ to keep compliance to the tutorial. Now this leads to a successful build as well, although it didn't before.

Removing the ...cygwin/bin directory from the include directories leads to a failed build again and the whole process has to be repeated. At least for me it worked this way.

el platin
  • 11
  • 3