gradle / gradle-native

The home of Gradle's support for natively compiled languages
https://blog.gradle.org/introducing-the-new-cpp-plugins
Apache License 2.0
92 stars 8 forks source link

“unexpected end-of-file found” issue on Precompile Header compilation with Visual Studio #1040

Open imartinbe opened 7 years ago

imartinbe commented 7 years ago

When compiling projects in Visual Studio 2012 with precompiled header, for some projects the build fails with returning an error

pchGenerated\prefix-headers.cpp(1) fatal error C1004: unexpected end-of-file found

This issue comes from missing CRLF at the end of the 2 files generated : prefix-headers.cpp and prefix-headers.h

Expected Behavior

The files prefix-headers.cpp and prefix-headers.h in build\tmp\compile*CppPreCompiledHeader\pchGenerated should end both** by a CRLF like: prefix-header.cpp : #include "prefix-headers.h"\r\n prefix-header.h: #include "pch.h"\r\n

Current Behavior

In the 2 files there is no CRLF after the unique instruction line

Context

I am trying to migrate an existing Visual Studio project onto gradle to be able to compile it on both Windows & Linux. I am stuck with the compilation of the precompiled headers.

Steps to Reproduce (for bugs)

It occurs with my project, but not with the one in the gradle distribution sample... It is difficult then to find a simple project where it fails...

Your Environment

Windows 7 Visual Studio 2012 Gradle 3.2.1 JDK 1.8u112

big-guy commented 7 years ago

Hmm, does the last file included in the prefix-header not have CRLF for your real project? That might be why the sample works.

imartinbe commented 7 years ago

You mean the pch.h ? In our case it well contains a CRLF at the end... When compiling using the command described in gradle --info details, I initially get the error; when manually adding the CRLFs, it compiles fine.

imartinbe commented 7 years ago

PS : cf also discussion I had with Gary Hale : https://discuss.gradle.org/t/unexpected-end-of-file-found-issue-on-precompile-header-compilation-with-visual-studio/21023/2

big-guy commented 7 years ago

Ah, good. Gary originally worked on this. Would you be interested in contributing a fix?

Have you been able to reproduce the issue with the pre-compiled-headers sample that comes in the Gradle distribution?

imartinbe commented 7 years ago

OK, I was able to reproduce it with the sample. It comes from the '/Za' compiler argument we add. If you change the build.gradle for the hello component like this, you will get the error.

hello(NativeLibrarySpec) {
    sources {
        cpp {
            preCompiledHeader "pch.h"
        }
    }
    binaries.all {
        cppCompiler.args ('/Za')
    }
}

This flag forces the code to follow ANSI C and ANSI C++ standards.