easy-build flow: on linux, if both GCC and Clang are installed, build fails because CMake picks GCC
⚠️ Issues not using this template will be systematically closed.
Describe the bug On Linux a default build will fail because CMake selects GCC instead of Clang
To Reproduce Steps to reproduce the behavior:
- On linux, where both GCC and Clang are installed, run
./build.sh release
Expected behavior When clang is available, Filament should be built.
Screenshots If applicable, add screenshots to help explain your problem.
Logs If applicable, copy full logs from your console here. Please do not use screenshots of logs, copy them as text, use gist or attach an uncompressed file.
$ ./build.sh release
Building release in out/cmake-release...
-- The C compiler identification is GNU 14.2.0
-- The CXX compiler identification is GNU 14.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:286 (message):
Detected C compiler GNU is unsupported
-- Configuring incomplete, errors occurred!
Desktop (please complete the following information):
- OS: Linux
- GPU: n/a
- Backend: n/a
Smartphone (please complete the following information):
- Device: n/a
- OS: n/a
Additional context Add any other context about the problem here.
I think that is in expected, you need to tell Filament where is clang if your default compiler is not clang. You can refer to here to see how to specify the compiler path:
CC=/usr/bin/clang CXX=/usr/bin/clang++ CXXFLAGS=-stdlib=libc++ ./build.sh release
I only got as far as using the "easy build" flow.
https://github.com/google/filament/blob/main/BUILDING.md#easy-build
I made a fresh docker image based on Ubuntu Noble 24.04, installed cmake, ninja-build, gcc, and clang.
Then specifying the CC and CXX and CXXFLAGS as suggested also fails:
# CC=/usr/bin/clang CXX=/usr/bin/clang++ CXXFLAGS=-stdlib=libc++ ./build.sh -c release
Cleaning build directories...
Building release in out/cmake-release...
-- The C compiler identification is Clang 18.1.3
-- The CXX compiler identification is Clang 18.1.3
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ - broken
CMake Error at /usr/share/cmake-3.28/Modules/CMakeTestCXXCompiler.cmake:60 (message):
The C++ compiler
"/usr/bin/clang++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: '/src/filament/out/cmake-release/CMakeFiles/CMakeScratch/TryCompile-rZUKFq'
Run Build Command(s): /usr/bin/ninja -v cmTC_13331
[1/2] /usr/bin/clang++ -stdlib=libc++ -MD -MT CMakeFiles/cmTC_13331.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_13331.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_13331.dir/testCXXCompiler.cxx.o -c /src/filament/out/cmake-release/CMakeFiles/CMakeScratch/TryCompile-rZUKFq/testCXXCompiler.cxx
[2/2] : && /usr/bin/clang++ -stdlib=libc++ CMakeFiles/cmTC_13331.dir/testCXXCompiler.cxx.o -o cmTC_13331 && :
FAILED: cmTC_13331
: && /usr/bin/clang++ -stdlib=libc++ CMakeFiles/cmTC_13331.dir/testCXXCompiler.cxx.o -o cmTC_13331 && :
/usr/bin/ld: cannot find -lc++: No such file or directory
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:17 (project)
-- Configuring incomplete, errors occurred!
This is probably just a documentation issue.
When I modify the command line to use -libstdc++ I get past configuration but fail compilation because it can't find the C++ headers.
CC=/usr/bin/clang CXX=/usr/bin/clang++ CXXFLAGS=-stdlib=libstdc++ ./build.sh -c release | tee build.log
I'm attaching the build.log file.
So in the BUILD instructions, there are some dependencies. Can you try installing them and try again? (You'll have to remove the out directory). Note that the instructions are based on clang-14. For your case, you'll want to replace all the 14 with 18.
Instead of export, can you also try update-alternatives instructions also on the same page. Either way should work.
I agree it should be the dependency issue since the specifying CC= method works in my docker env.
You can check out my CL for the Dockerfile I used: cl/735804622