"Unrecognized command-line option" during Java Native Access build from sources

Viewed 114

I must build the following project from sources:

git clone --depth 1 --branch 5.5.0  https://github.com/java-native-access/jna.git

For that I install required libraries:

sudo apt-get install autoconf autogen
sudo apt-get install libtool

then run "ant" command with following error:

native:
     [exec] gcc -m64 -W -Wall -Wno-unused -Wno-parentheses -fPIC  -O2 -fno-omit-frame-pointer -fno-strict-aliasing  -D_REENTRANT -DHAVE_PROTECTION -I"/home/katya/java/include" -I"/home/katya/java/include/linux" -I"/home/katya/tmp_work/jna/build/headers" -I/home/katya/tmp_work/jna/build/native-linux-x86-64/libffi/include -DJNA_JNI_VERSION='"6.1.0"' -DCHECKSUM='"147a998f0cbc89681a1ae6c0dd121629"' -Wno-unknown-warning-option -Werror -Wno-clobbered -Wno-unused-variable -c dispatch.c -o /home/katya/tmp_work/jna/build/native-linux-x86-64/dispatch.o
     [exec] In file included from dispatch.h:33,
     [exec]                  from dispatch.c:30:
     [exec] dispatch.c: In function ‘dispatch_direct’:
     [exec] dispatch.c:1770:23: error: ‘alloca’ bound is unknown [-Werror=alloca-larger-than=]
     [exec]  1770 |             args[i] = alloca(data->cif.arg_types[i]->size);
     [exec]       |                       ^~~~~~
     [exec] dispatch.c:1796:23: error: ‘alloca’ bound is unknown [-Werror=alloca-larger-than=]
     [exec]  1796 |             args[i] = alloca(data->cif.arg_types[i]->size);
     [exec]       |                       ^~~~~~
     [exec] dispatch.c: At top level:
     [exec] cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
     [exec] cc1: all warnings being treated as errors
     [exec] make: *** [Makefile:430: /home/katya/tmp_work/jna/build/native-linux-x86-64/dispatch.o] Error 1

BUILD FAILED
/home/katya/tmp_work/jna/build.xml:1003: exec returned: 2

Could you tell me what is wrong and how to fix that?

1 Answers

The problem is the following: alloca is a function that needs to be used with care. On gcc versions newer or equal to 10 a warning is issued if the compiler can't prove, that the usage is save. JNA is build with "-Werror", which causes all warnings to be treated as errors.

If you insist to build 5.5.0, you can modify native/Makefile and remove the modification of "LOC_CC_OPTS", which added the mentioned warning flag.

However I strongly suggest, that you move to the most recent version of JNA (this problem was fixed in 5.6.0, released about one year ago), as the releases contain fixes, you might need.

Related