Include paths during native compilation with Visual Studio have duplicate entries appended for each file compiled

Hello all,

Before I dive in, I’m running with the following environment:

Visual Studio 2010, SP1 Windows 7, 64-bit

Windows 7 SDK Gradle 2.1, revision e6cf70745ac11fa943e19294d19a2c527a669a53 Groovy 2.3.6 JRE 1.7 Update 60

When building native C++ source sets that involve the compilation of more than one file, I’ve noticed that a new instance of

“/IC:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include” “/IC:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include”

appears to be added to the include path passed to the compiler via the generated options.txt file. This seems to be cumulative in nature, i.e.

File 1 will have one instance of the above appended to the include path. File 2 will have two instances … File n will have n instances, and so on.

For small source sets this isn’t an issue outside of additional scrolling to get to the bottom of the options.txt file. When compiling larger source sets, the include path grows to the point where the options.txt file grows past 32KB, which is what I’ve read to be the maximum size for CL.exe command files. CL’s response to this is to throw a Buffer Overflow exception (BEX64) and crash, which is something I’d obviously like to avoid :slight_smile:

I have a small, 2 source file project that demonstrates what I just described. The following build.gradle compiles two files in the HelloWorld source set into a single HelloWorld executable:

apply plugin: 'cpp'
apply plugin: 'visual-studio'
  // Define native build model for all projects.
model {
 platforms {
  Windows_x86 {
   architecture "x86"
   operatingSystem "windows"
  }
  Windows_x64 {
   architecture "x64"
   operatingSystem "windows"
  }
 }
    buildTypes {
  Debug
  Release
 }
 }
     executables {
 HelloWorld
 {
  targetPlatforms "Windows_x86", "Windows_x64"
  targetBuildTypes "Debug", "Release"
 }
}
  sources {
 HelloWorld {
  cpp {
   source {
    srcDir './'
    include '**/*.cpp'
   }
  }
 }
}

The options.txt that gets generated for the second file in the source set looks like this:

/TP /nologo /c /IC:\redatced\HelloWorld\headers “/IC:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include” “/IC:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include” “/IC:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include” “/IC:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include” C:\redacted\HelloWorld\helloworldclass.cpp /FoC:\redacted\HelloWorld\build\objs\helloWorldExecutable\windows_x86Release\HelloWorldCpp\42glttfdr6o6c8ojijflvv7sk\helloworldclass.obj

I’ve tried searching a bit for info on this problem, and haven’t come across anything that points to a solution. I am going to try and work around it by splitting my project into several smaller source sets (I’m unsure of whether or not this will even work), but I would still LOVE some help in determining if there’s something I am doing to cause it or if I’m up against a genuine issue.

Thanks! Paul

I’ve managed to work around the problem by splitting the large source set I’m working with in my real project into 3 smaller source sets. I still see the growing include path problem in the generated options.txt files, but they’re small enough to prevent CL.exe from crashing. Is there something I’m doing that causes this to happen?