Skip to content

easy-build flow: on linux, if both GCC and Clang are installed, build fails because CMake picks GCC #8515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dneto0 opened this issue Mar 11, 2025 · 7 comments · May be fixed by #8522
Open
Assignees
Labels
build Build & build system issues

Comments

@dneto0
Copy link

dneto0 commented Mar 11, 2025

⚠️ 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:

  1. 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.

@show50726
Copy link
Contributor

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

@dneto0
Copy link
Author

dneto0 commented Mar 11, 2025

I only got as far as using the "easy build" flow.
https://github.com/google/filament/blob/main/BUILDING.md#easy-build

@dneto0 dneto0 changed the title on linux, if both GCC and Clang are installed, build fails because CMake picks GCC easy-build flow: on linux, if both GCC and Clang are installed, build fails because CMake picks GCC Mar 11, 2025
@dneto0
Copy link
Author

dneto0 commented Mar 11, 2025

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.

@dneto0
Copy link
Author

dneto0 commented Mar 11, 2025

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.

build.log

@poweifeng
Copy link
Contributor

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.

@show50726
Copy link
Contributor

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

dneto0 added a commit to dneto0/filament that referenced this issue Mar 13, 2025
CMake will default to GCC if it's available.
Force use of the latest Clang instead.
This can be overridden with CC, CXX, and CXXFLAGS

Fixed: google#8515
dneto0 added a commit to dneto0/filament that referenced this issue Mar 13, 2025
CMake will default to GCC if it's available.
Force use of the latest Clang instead.
This can be overridden with CC, CXX, and CXXFLAGS

Fixed: google#8515
@dneto0 dneto0 linked a pull request Mar 13, 2025 that will close this issue
dneto0 added a commit to dneto0/filament that referenced this issue Mar 13, 2025
CMake will default to GCC if it's available.
Force use of the oldest installed Clang instead.
This can be overridden with CC, CXX, and CXXFLAGS

Fixed: google#8515
@pixelflinger pixelflinger added the build Build & build system issues label Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Build & build system issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@pixelflinger @dneto0 @show50726 @poweifeng and others