graph-prototype icon indicating copy to clipboard operation
graph-prototype copied to clipboard

cmake: when no compiler specified, defaults to `gcc`, but then use libstdc++ -> default build doesn't build

Open marcusmueller opened this issue 6 months ago • 1 comments

default Docker build as specified in DEVELOPER.md does not work, because cmake as configured seems to use libc++ with the default GCC build. Something's wrong with the cmake logic that determines that stdlib flag, and on first sight it's not clear what it is – the CMAKE_COMPILER_ID against clang and should not trigger on "no flags".

podman run -it --rm ghcr.io/fair-acc/gr4-build-container bash
cd
git clone --recursive https://github.com/fair-acc/gnuradio4
cd gnuradio
cmake -S . -B build

yields

Make Error at /usr/share/cmake-3.31/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "/usr/bin/gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: '/tmp/gnuradio4/build/CMakeFiles/CMakeScratch/TryCompile-P98Tew'

    Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_a5a9a/fast
    /usr/bin/gmake  -f CMakeFiles/cmTC_a5a9a.dir/build.make CMakeFiles/cmTC_a5a9a.dir/build
    gmake[1]: Entering directory '/tmp/gnuradio4/build/CMakeFiles/CMakeScratch/TryCompile-P98Tew'
    Building C object CMakeFiles/cmTC_a5a9a.dir/testCCompiler.c.o
    /usr/bin/gcc   -fPIE -o CMakeFiles/cmTC_a5a9a.dir/testCCompiler.c.o -c /tmp/gnuradio4/build/CMakeFiles/CMakeScratch/TryCompile-P98Tew/testCCompiler.c
    Linking C executable cmTC_a5a9a
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a5a9a.dir/link.txt --verbose=1
    gcc: error: unrecognized command-line option ‘-stdlib=libc++’
    /usr/bin/gcc  -stdlib=libc++ -lc++  CMakeFiles/cmTC_a5a9a.dir/testCCompiler.c.o -o cmTC_a5a9a
    gmake[1]: *** [CMakeFiles/cmTC_a5a9a.dir/build.make:102: cmTC_a5a9a] Error 1
    gmake[1]: Leaving directory '/tmp/gnuradio4/build/CMakeFiles/CMakeScratch/TryCompile-P98Tew'
    gmake: *** [Makefile:134: cmTC_a5a9a/fast] Error 2





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  build/_deps/pffft-src/CMakeLists.txt:2 (project)

marcusmueller avatar Jul 18 '25 14:07 marcusmueller

open investigative question: why is gcc (not g++) being invoked with -stdlib=libc++ -lc++.

  • ah it's `add_compile_option

Also, Alex says it should default to Ninja, but it doesn't.

Possible solution: Don't use add_compile_options, which affects all languages (C, C++, FORTRAN,…) but add these definitions to the individual targets as language-dependent generator expression to the interface of the core target?

marcusmueller avatar Jul 18 '25 14:07 marcusmueller