Better instructions for building with MSVC

27 views
Skip to first unread message

David Hoyt

unread,
May 15, 2013, 2:50:23 AM5/15/13
to jna-...@googlegroups.com
I've tried to follow the instructions for using MSVC to build the native portions. But I don't see anything picking it up and using it (I know it's available in the environment). Can you provide explicit instructions please for configuring a proper environment?

David Hoyt

unread,
May 15, 2013, 3:07:45 AM5/15/13
to jna-...@googlegroups.com
Well, I got it to compile w/ GCC on Windows (using msys/mingw). It still choked w/ MSVC (the config.log didn't provide anything interesting or of note -- I see that it's using cc.sh which apparently is a wrapper around MS' C compiler (cl.exe) to translate gcc-ish options to cl.exe and friends). Lesson learned for others:
  • Install and use ant from the command line
    • Trying to use ant from your IDE can spell trouble

Timothy Wall

unread,
May 15, 2013, 8:22:25 AM5/15/13
to jna-...@googlegroups.com
I thought that was a given :) Most IDEs are miles away from being portable between people.

Timothy Wall

unread,
May 15, 2013, 9:02:02 AM5/15/13
to jna-...@googlegroups.com
Feel free to augment the instructions.

I use cygwin for win32, MSVC for win64. By default the Makefile passes "cc.sh" and "ld.sh" to libffi, both of which expect to find cl.exe and link.exe in the path, along with sane definitions of INCLUDE and LIB. To force the makefile to use mingw64, you just have to uncomment a line setting CC to gcc instead of cc.sh.

Problem with mingw64 is that it doesn't have SEH, which is used for protected mode (i.e. throw a Java exception instead of crashing).

On May 15, 2013, at 2:50 AM, David Hoyt wrote:

> I've tried to follow the instructions for using MSVC to build the native portions. But I don't see anything picking it up and using it (I know it's available in the environment). Can you provide explicit instructions please for configuring a proper environment?
>
> --
> You received this message because you are subscribed to the Google Groups "Java Native Access" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

David Hoyt

unread,
May 15, 2013, 12:52:29 PM5/15/13
to jna-...@googlegroups.com
IDEs (the ones I use these days at least -- IntelliJ and Netbeans) bundle stock ant w/ them (maven too for Netbeans) so you don't need to go out and independently download and setup those tools as well.

I had added the cygwin tools to the system path (and then msys/mingw -- which is just a fork of cygwin albeit a fork from a long time ago now), but that failed miserably. Then I had to run dos2unix on the autotool scripts presumably b/c I had forgotten to disable auto crlf in git (I didn't verify that). That was to get past line ending issues.

I actually have a rather customized msys/mingw environment that I made for OSSBuild (open source software build environment) with a custom-built gcc based on gcc 4.5.2 via the mingw64 folks. I've built hundreds of packages w/ this environment.

In the end, using ant from within my custom msys environment shell was what worked.

David Hoyt

unread,
May 15, 2013, 1:09:46 PM5/15/13
to jna-...@googlegroups.com
Define "sane." My OSSBuild environment actually replicates what the Visual Studio command prompts do -- so the LIB, INCLUDE, and PATH env vars. are updated to have the exact same paths on them that using the VS command prompt would have (well I do add a couple more). I went to great lengths to follow suit (including reading the registry in the same way). See https://github.com/ossbuild/ossbuild-env/blob/master/windows/packages/msys/ossbuild/ms-tools.sh#L481 for the details. In the end, they look like:

LIB=/c/Program Files (x86)/Microsoft Visual Studio 10.0/VC/LIB:/c/Program Files (x86)/Microsoft Visual Studio 10.0/VC/ATLMFC/LIB:/c/Program Files/Microsoft SDKs/Windows/v6.0A/lib:/c/Program Files/Java/jdk1.7.0_15/lib:/c/Program Files (x86)/Windows Installer XML v3.5/SDK/lib

INCLUDE=/c/Program Files (x86)/Microsoft Visual Studio 10.0/VC/INCLUDE:/c/Program Files (x86)/Microsoft Visual Studio 10.0/VC/ATLMFC/INCLUDE:/c/Program Files/Microsoft SDKs/Windows/v6.0A/include:/c/Program Files/Java/jdk1.7.0
_15/include:/c/Program Files (x86)/Windows Installer XML v3.5/SDK/inc

It should be close enough to the recommended Windows dev environment. I do use an older Platform SDK -- the one bundled w/ Visual Studio. In my case, v6.0, not v7.0. I wouldn't think that'd make a big difference (not for JNA and libffi's needs). At any rate, when I use this environment to compile the JNA native lib, the MS tools version doesn't get through configure. Presumably there's something in the LIB/INCLUDE env vars it didn't like. The error was that it couldn't create an executable (and config.log was not helpful at all). I know those are on the path:

dhoyt@tinuviel /d/work/jna
$ cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

dhoyt@tinuviel /d/work/jna
$ ld
ld: no input files

Timothy Wall

unread,
May 17, 2013, 2:30:28 AM5/17/13
to jna-...@googlegroups.com
My settings on win7 (as seen from cygwin; ant launched from cygwin bash):

LIB=c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/lib/x86_amd64;c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/lib/amd64;c:/Program Files/Microsoft SDKs/Windows/v7.1/lib/x64
INCLUDE=c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include;c:/Program Files/Microsoft SDKs/Windows/v7.1/include

I notice that your LIB is missing "amd64" and "x64".

SDK 6 vs 7 doesn't matter; I have both configurations and I haven't seen issues.
Reply all
Reply to author
Forward
0 new messages