"gradle-native-samples" project failing with "fatal error: 'iostream' file not found" on Mac OS X 10.13


(surfing) #1

I’m not new to Gradle, but am new to building C++ in Gradle.

I’ve tried several examples in the “gradle-native-samples” project on github and get this error:
“fatal error: ‘iostream’ file not found”

I believe that Gradle is launching the clang compiler without specifying the standard includes, so I’m stumbling around trying to add the includes as part of the “cppCompiler.args”, but without success thus far.

I’m working on Mac OS X 10.13 and XCode 9.

I’ll add more if I figure this out, but any suggestions would be helpful…


(surfing) #2

BTW, I’m using the latest Gradle 4.2.1, but I tried 4.1.


(Pepper Lebeck-Jobe) #3

Thanks for writing in @bit.

Can you give us a little more information?

  • Are you using the ./gradlew wrapper in the samples to make sure the version of Gradle being used is one compatible with the samples?
  • What version of the JVM are you running?
  • Can you list the exact steps you took to get the error? For example:
    • git clone https://github.com/gradle/native-samples
    • cd native-samples
    • ./gradlew assemble

Or whatever you actually ran.

Thanks,
Pepper


(Pepper Lebeck-Jobe) #4

Oh, and if you can provide a build scan, we could see a bunch of information that would help us debug this issue further. If not, could you run Gradle with the -s argument and paste the stack trace in here?


(surfing) #5

Thanks for the quick response.

My Java is:
java -version
java version "1.8.0_121"
Java™ SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot™ 64-Bit Server VM (build 25.121-b13, mixed mode)

I just deleted and tried again from scratch. Here are the steps I took:

git clone https://github.com/gradle/native-samples
cd native-samples/cpp/executable/
./gradlew assemble

Result:

Task :compileDebugCpp
…native-samples/cpp/executable/src/main/cpp/main.cpp:1:10: fatal error: ‘iostream’ file not found
#include
^~~~~~~~~~
1 error generated.

Other info: Mac OS X 10.13 (High Sierra) and Xcode 9.

I’m assuming it’s using clang (can I debug and see the exact command-line args that Gradle is using?).


(Pepper Lebeck-Jobe) #6

If you run:
./gradlew clean

followed by
./gradlew assemble -d

You should see a line (among a lot of output) that contains org.gradle.process.internal.DefaultExecHandle and shows the entire command-line used for invoking clang. Of special interest will be the path to the options.txt file which contains the command-line options passed to clang.

Also, if you could upload a buildscan, it would be pretty easy to troubleshoot remotely.

I haven’t actually upgraded to High Sierra yet, so I’m not sure if something might have moved.

Thanks,
Pepper


(surfing) #7

Ah, thanks for pointing out what to look for. The “options.txt” tip was what lead me in the right direction.

The problem was that I had previously built clang++ from source. Gradle was using that. I removed the custom clang++ from the path and everything works fine.

Thanks again.