Native Compilation with MSVC and ARM


(Jay McGaffigan) #1

I’m trying to compile a set of Cpp Unit tests for an ARM based platform. In compiling with visual studio we are getting an error

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xkeycheck.h(250) : fatal error C1189: #error : The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the forbidden macro.

I’d like to not have the MSVC include files get added to the options.txt -IC list. How do I make that happen? I’ve tried below. But to no avail.

model {
toolChains {
visualCpp(VisualCpp) {
eachPlatform { toolChain ->
cppCompiler.withArguments { args ->
def sdkIncludes = args.findAll { it ==~ /.8.1./ }
def sysIncludes = args.findAll { it ==~ /.Microsoft./ }
args.remove(sdkIncludes)
args.remove(sysIncludes)
}
}
}
}
binaries {
withType(NativeExecutableSpec) {
cCompiler.args "/Zi"
cppCompiler.args “/Zi”
}

    all {
        if (toolChain in VisualCpp) {
            ["STM32F412xG", "UNITTEST"].each { arg -> cCompiler.define arg }
            ["STM32F412xG", "UNITTEST", "WIN32", "_VC80_UPGRADE=0x0600", "_DEBUG", "STDC_WANT_SECURE_LIB", "_MBCS"].each { arg -> cppCompiler.define arg }
            ['/FS', '/GS', '/analyze-', '/W3', '/Zc:wchar_t', '/Gm-', '/Od', '/fp:precise', '/errorReport:prompt', '/WX-', '/Zc:forScope', '/RTC1', '/Gd', '/Oy-', '/MDd', '/EHsc', '/nologo'].each { arg -> cppCompiler.args arg }
            ["/DEBUG"].each { arg -> linker.args arg }
        }
        linker.args "winmm.lib"
    }
}

Thanks!
Jay


(Daniel Lacasse) #2

Hi Jay,

Thanks for raising this issue. I belive this is a limitation with the current modeling for Visual Studio. You can raise an issue on github for future enhancement of the model.

A possible workaround would be to configure the VisualCpp toolchain to use an invalid windowSdkDir path which would result in not finding any include although the sdk include path is added inside the options.txt file.

Don’t hesitate to ask more questions,

Daniel


(Jay McGaffigan) #3

Thanks Daniel,
That doesn’t seem to work. In trying to set the windowsSdkDir i get an error saying that there is no valid SDK there and it doesn’t try to compile anything.


(Daniel Lacasse) #4

Thanks for the feedback Jay.

Unfortunately, this is less than ideal to fix but it is possible to fix. The VisualCpp implementation will try to locate the SDK according the the path you specified. The locator code will eventually make it’s way to the isWindowsSdk method. To validate the Windows SDK, Gradle tries to find rc.exe and kernel32.lib. Try to create the following files relative to the root you specified for windowsSdk property:

  • bin/rc.exe
  • lib/kernel32.lib

With those two file (can be simple empty text file) the check should succeed and will use this new, mostly empty, folder as the Windows SDK. It should pick up any files from it. Just be careful with the kernel32.lib file where you will most likely have to specify the real one if you need it.

I opened an issue for you to track this limitation.

Daniel