This builds the library based on the Visual C++ compiler, but can be adjusted to work without if needed.
JNA uses the Microsoft Visual Studio C++ compiler (MSVC) to compile
native bits when MSVC is detected in the environment. The MSVC compiler provides
structured event handling (SEH), which allows JNA to trap native faults when
run in protected mode. It does this using libffi's native/libffi/msvcc.sh
wrapper script, which converts Makefile gcc commands to MSVC-compatible
(e.g. cl.exe, etc) calls.
For x86, x86_64, you will still need to install mingw64 in order to compile a small bit of inline assembly.
To use the MSVC compiler, the appropriate x86 or x86_64 versions
of cl.exe/ml(64).exe/link.exe must be in your PATH
and that the INCLUDE and LIB environment variables are set properly.
We'll set these automatically using VsDevCmd.bat
Prefer to use bash instead?
export MSVC="/c/Program Files (x86)/Microsoft Visual Studio 10.0/vc"
export WSDK="/c/Program Files (x86)/Microsoft SDKs/Windows/v7.0A"
export WSDK_64="/c/Program Files/Microsoft SDKs/Windows/v7.1"
export INCLUDE="$(cygpath -m "$MSVC")/include;$(cygpath -m "$WSDK")/include"
# for x86_64 target
export LIB="$(cygpath -m "$MSVC")/lib/amd64;$(cygpath -m "$WSDK_64")/lib/x64"
# for x86 target
export LIB="$(cygpath -m "$MSVC")/lib;$(cygpath -m "$WSDK")/lib"Warning: The below steps are for cmd only. If you're choosing to use bash, you'll need to adjust each command as needed.
Starting pont: A clean Windows 10 64-bit Installation with all patches
- Install "Visual Studio Community 2019" or the "Build Tools for Visual Studio 2019"
(https://visualstudio.microsoft.com/downloads/)
- Windows 10 SDK
- MSVC v142 - VS 2019 C++-x64/x86-Buildtools
- MSVC v142 - VS 2019 C++-ARM64-Buildtools
- Windows Universal CRT SDK
- Install AdoptOpenJDK 8 for the target architecture (https://adoptopenjdk.net/index.html)
- Install ant (https://ant.apache.org/bindownload.cgi).
- Install Cygwin 64 Bit (https://cygwin.com/install.html)
-
make
-
automake
-
automake1.15
-
libtool
-
git
-
gcc-g++ (See table)
x86_64 x86 aarch64 gcc-g++mingw64-x86_64-gcc-g++mingw64-x86_64-gcc-coregcc-g++mingw64-i686-gcc-g++mingw64-i686-gcc-coregcc-g++
-
Note: The paths below are samples and depend on the exact versions
installed. For example for "Visual Studio Community 2019" vcvarsall.bat can
be found here:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat,
while for "Build Tools for Visual Studio 2019" the file is found here:
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat.
-
Open
cmdfor the following actions -
Point
JAVA_HOMEto the root of the target JDK:set JAVA_HOME=C:\Program Files\AdoptOpenJDK\jdk-8.0.222.10-hotspot
set JAVA_HOME=C:\Program Files (x86)\AdoptOpenJDK\jdk-8.0.222.10-hotspot
Native builds only. For cross-compiling, use
x86_64.set JAVA_HOME=%USERPROFILE%\jdk-16-ea+19-windows-aarch64
-
Ensure
antis accessible from thePATHset PATH=%USERPROFILE%\apache-ant-1.9.11\bin;%PATH%
-
Include 64 Bit Cygwin in the path
set PATH=C:\cygwin64\bin\;%PATH%
-
Setup the Visual Studio build environment using
vcvarsallin<host>_<target>notation:"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64_x86"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64_arm64 -
Run the build
ant
... or if cross-compiling, specify the target architecture and only build the native library, e.g:
ant -Dos.prefix=win32-aarch64 native
To build without Visual C++, using only Cygwin, just skip step 5 and skip installing the Visual C++ Build Tools 2019 . (Cygwin currently cannot build aarch64 binaries, MSVC is needed)
- For native compiling or linking errors for MSVC builds after
VsDevCmd.batwas run for a different/wrong architecture:- Close and reopen
cmd - Configure
PATH,JAVA_HOMEagain per target architecture. - Run
ant clean - Start the build again.
- Close and reopen
- For native compiling or linking errors for MSVC builds, toggle on debug mode in
native/libffi/msvcc.sh:- verbose= + verbose=1
- Re-run ant with detailed output:
ant -DEXTRA_MAKE_OPTS="--debug=v"