"gtest/gtest.h" not found in TypeRef.cpp while compiling the compiler

Hi Developers,

I was trying to compile the swift compiler with Xcode 12.4 and macOS 11.2 installed (I didn't have the command line tool installed)

However, during the compilation process, the following error popped up:

/Users/yujian/Code/swift-source/swift/unittests/Reflection/TypeRef.cpp:15:10: fatal error: 'gtest/gtest.h' file not found

#include "gtest/gtest.h"

         ^~~~~~~~~~~~~~~

1 error generated.

(For the full error message including the command invoked by the utils/build-script, please click here)

I tried to solve this by installing google test on my Mac and now gtest/gtest.h is located in /usr/local/include.

However, when I tried to build the swift compiler again, the same error popped up again.

I used the following command to build the compiler:

utils/build-script --skip-build-benchmarks \
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
--sccache --release-debuginfo --swift-disable-dead-stripping --test \
--xcode

and here's the link to the output of utils/update-checkout --dump-hashes
https://gist.github.com/Xkinler/be478c9a45d0320a80f56269cca5d7bb

Could you please help me with this? Thank you!

1 Like

Update: The error still exists in a clean build

1 Like

I don't know exactly the problem but trying to narrow it down maybe you could test if that still happens if you build without --test flag

2 Likes

Hi @LucianoPAlmeida

Thank you for your reply.

I have switched to build with ninja and everything works fine now.

Thank you again for your help!

I also have this problem. Does anyone know how to address this issue?

I tried installing gtest via brew install googletest, but I still receive the same error.


Also, it looks like the file that throws the error is different every time. I have commented on this issue and listed the names of the different files I've gotten this error from.


This does cause the build to succeed.


Doing this I was able to successfully compile and test the compiler.

As mentioned on the issue ticket, I think PR https://github.com/apple/swift/pull/36971 could be a fix for the issue :)

2 Likes

@LucianoPAlmeida @justinfargnoli It's merged on main branch :slight_smile:

2 Likes