Search code examples
jna

How can I compile JNA's native bits on windows for 32- and 64-bit targets?


I want to compile JNA library on 32-bit Cygwin or on 32-bit Debian Linux using -Dskip-native=false parameter. I installed the required packages, but it can't be compiled. It can be compiled on 64-bit Cygwin or 64-bit Debian Linux without any problem (for 64-bit target), but can't be compiled on 32-bit platforms. I also tried to compile the sources on jna-4.2.1/dist/src-full folder, but it couldn't be compiled.

I use the following parameters for 32-bit target.

export ANT_OPTS="-d32 -Dos.prefix=win32-x86 -Dskip-native=false"

I got the following error messages on 64-bit Cygwin (using the same parameters).

 [exec] /cygdrive/d/Projects/jna-4.2.1/dist/src-full/native/libffi/src/x86/win64.S: Assembler messages:
 [exec] /cygdrive/d/Projects/jna-4.2.1/dist/src-full/native/libffi/src/x86/win64.S:286: Error: bad register name `%r11'
 [exec] /cygdrive/d/Projects/jna-4.2.1/dist/src-full/native/libffi/src/x86/win64.S:288: Error: bad register name `%rcx'
 [exec] /cygdrive/d/Projects/jna-4.2.1/dist/src-full/native/libffi/src/x86/win64.S:291: Error: bad register name `%rsp)'
 [exec] /cygdrive/d/Projects/jna-4.2.1/dist/src-full/native/libffi/src/x86/win64.S:294: Error: bad register name `%r11'

 ...
 [exec] /cygdrive/d/Projects/jna-4.2.1/dist/src-full/native/libffi/src/x86/win64.S:516: Error: bad register name `%rbp'
 [exec] /cygdrive/d/Projects/jna-4.2.1/dist/src-full/native/libffi/src/x86/win64.S:517: Error: unsupported instruction `ret'
 [exec] /cygdrive/d/Projects/jna-4.2.1/dist/src-full/native/libffi/src/x86/win64.S:518: Warning: zero assumed for missing expression
 [exec] /cygdrive/d/Projects/jna-4.2.1/dist/src-full/native/libffi/src/x86/win64.S:518: Warning: zero assumed for missing expression
 [exec] Makefile:1345: recipe for target 'src/x86/win64.lo' failed
 [exec] make[3]: Leaving directory '/cygdrive/d/Projects/jna-4.2.1/dist/src-full/build/native-win32-x86/libffi'
 [exec] Makefile:1603: recipe for target 'all-recursive' failed
 [exec] make[2]: Leaving directory '/cygdrive/d/Projects/jna-4.2.1/dist/src-full/build/native-win32-x86/libffi'
 [exec] Makefile:741: recipe for target 'all' failed
 [exec] make[1]: Leaving directory '/cygdrive/d/Projects/jna-4.2.1/dist/src-full/build/native-win32-x86/libffi'
 [exec] Makefile:449: recipe for target '../build/native-win32-x86/libffi/.libs/libffi.a' failed
 [exec] make[3]: *** [src/x86/win64.lo] Error 1
 [exec] make[2]: *** [all-recursive] Error 1
 [exec] make[1]: *** [all] Error 2
 [exec] make: *** [../build/native-win32-x86/libffi/.libs/libffi.a] Error 2

 BUILD FAILED
 D:\Projects\jna-4.2.1\dist\src-full\build.xml:813: exec returned: 2

I get the following errors on 32-bit Cygwin.

 [echo] os.prefix=win32-x86
 [echo] os.name=Windows 7
 [echo] os.arch=x86 (little)
 [echo] build=build
 [echo] build.native=D:\Projects\jna-4.2.1\dist\src-full\build\native-win32-x86

-setup:

compile:
[javac] Compiling 59 source files to D:\Projects\jna-4.2.1\dist\src-full\build\classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 warning

javah:

-native-api-check:

:rsrc:

rsrc:
 [copy] Copying 1 file to D:\Projects\jna-4.2.1\dist\src-full\build\native-win32-x86

native:
 [exec] Generating configure
 [exec] autoreconf-2.69: Entering directory `.'
 [exec] autoreconf-2.69: configure.ac: not using Gettext
 [exec] autoreconf-2.69: running: aclocal --force -I m4
 [exec] autoreconf-2.69: configure.ac: tracing
 [exec] autoreconf-2.69: running: libtoolize --copy --force
 [exec] libtoolize: putting auxiliary files in '.'.
 [exec] libtoolize: copying file './ltmain.sh'
 [exec] libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
 [exec] libtoolize: copying file 'm4/libtool.m4'
 [exec] libtoolize: copying file 'm4/ltoptions.m4'
 [exec] libtoolize: copying file 'm4/ltsugar.m4'
 [exec] libtoolize: copying file 'm4/ltversion.m4'
 [exec] libtoolize: copying file 'm4/lt~obsolete.m4'
 [exec] autoreconf-2.69: running: /usr/bin/autoconf-2.69 --force
 [exec] autoreconf-2.69: running: /usr/bin/autoheader-2.69 --force
 [exec] autoreconf-2.69: running: automake --add-missing --copy --force-missing
 [exec] Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/ at /usr/bin/automake-1.15 line 3936.
 [exec] configure.ac:31: installing './compile'
 [exec] configure.ac:19: installing './missing'
 [exec] Makefile.am: installing './depcomp'
 [exec] Configuring libffi (x86)
 [exec] autoreconf-2.69: Leaving directory `.'
 [exec] checking build system type... i686-pc-cygwin
 [exec] checking host system type... i686-pc-cygwin
 [exec] checking target system type... i686-pc-cygwin
 [exec] checking for gsed... sed
 [exec] checking for a BSD-compatible install... /usr/bin/install -c
 [exec] checking whether build environment is sane... yes
 [exec] checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
 [exec] checking for gawk... gawk
 [exec] checking whether make sets $(MAKE)... yes
 [exec] checking whether make supports nested variables... yes
 [exec] checking for gcc... i686-pc-mingw32-gcc
 [exec] checking whether the C compiler works... no
 [exec] configure: error: in `/cygdrive/d/Projects/jna-4.2.1/dist/src-full/build/native-win32-x86/libffi':
 [exec] configure: error: C compiler cannot create executables
 [exec] See `config.log' for more details
 [exec] Makefile:449: recipe for target '../build/native-win32-x86/libffi/.libs/libffi.a' failed
 [exec] make: *** [../build/native-win32-x86/libffi/.libs/libffi.a] Error 77

BUILD FAILED
D:\Projects\jna-4.2.1\dist\src-full\build.xml:813: exec returned: 2

Total time: 50 seconds

I couldn't understand why it says "[exec] checking whether the C compiler works... no" although I installed all development packages and lib packages on 32-bit Cygwin and although gcc works.

How can I compile jna's native libraries for 32-bit platforms?


Solution

  • According to config.log, configure is failing here:

    /cygdrive/d/Projects/jna-4.2.1/native/libffi/configure: line 3927: i686-pc-mingw32-gcc: command not found

    Make sure that your cross compiler is on your path or add CC=/path/to/your-cross-compiler to FFI_CONFIG.