I am building test executable with coverage enabled (GCC --coverage build and link flag). However I cannot locate the gcov tool to analyze the resulting .gcda files.
After much searching, it seems the GCC NIX package hides tools like gcov?
How are people getting C/C++ code test coverage metrics using Nix GCC toolchains in a Flox environment?
Using gcc-unwrapped as you suggest does give me gcov
$ which gcov
<path/to>/.flox/run/x86_64-linux.edt1.dev/bin/gcov
However now the linker is missing, so it’s using my host’s linker:
$ which ld
/usr/bin/ld
Here’s a MWE:
mkdir /tmp/dummy-flox-env
cd /tmp/dummy-flox-env
flox init
flox install cmake gcc-unwrapped
Write a dummy CMakeLists.txt file to just find and test the compiler:
cmake_minimum_required(VERSION 3.16)
project(dummy
LANGUAGES C CXX
)
Then I see CMake fails to link even their simple test app to test if the compiler works. Notice it’s using the host /usr/bin/ld.
$ CC=$(which gcc) CXX=$(which g++) cmake -S . -B build
-- The C compiler identification is GNU 14.3.0
-- The CXX compiler identification is GNU 14.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /tmp/dummy-flox-env/.flox/run/x86_64-linux.dummy-flox-env.dev/bin/gcc
-- Check for working C compiler: /tmp/dummy-flox-env/.flox/run/x86_64-linux.dummy-flox-env.dev/bin/gcc - broken
CMake Error at /nix/store/0vnarm4qjnj16dr3zj9kwq6bn79c0icn-cmake-3.31.7/share/cmake-3.31/Modules/CMakeTestCCompiler.cmake:67 (message):
The C compiler
"/tmp/dummy-flox-env/.flox/run/x86_64-linux.dummy-flox-env.dev/bin/gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: '/tmp/dummy-flox-env/build/CMakeFiles/CMakeScratch/TryCompile-hBSabD'
Run Build Command(s): /nix/store/0vnarm4qjnj16dr3zj9kwq6bn79c0icn-cmake-3.31.7/bin/cmake -E env VERBOSE=1 /usr/bin/make -f Makefile cmTC_43c1d/fast
/usr/bin/make -f CMakeFiles/cmTC_43c1d.dir/build.make CMakeFiles/cmTC_43c1d.dir/build
make[1]: Entering directory '/tmp/dummy-flox-env/build/CMakeFiles/CMakeScratch/TryCompile-hBSabD'
Building C object CMakeFiles/cmTC_43c1d.dir/testCCompiler.c.o
/tmp/dummy-flox-env/.flox/run/x86_64-linux.dummy-flox-env.dev/bin/gcc -o CMakeFiles/cmTC_43c1d.dir/testCCompiler.c.o -c /tmp/dummy-flox-env/build/CMakeFiles/CMakeScratch/TryCompile-hBSabD/testCCompiler.c
Linking C executable cmTC_43c1d
/nix/store/0vnarm4qjnj16dr3zj9kwq6bn79c0icn-cmake-3.31.7/bin/cmake -E cmake_link_script CMakeFiles/cmTC_43c1d.dir/link.txt --verbose=1
/usr/bin/ld: /nix/store/qdknxw57cwy1jkrhq7fzmiis73j42jv6-gcc-14.3.0/libexec/gcc/x86_64-unknown-linux-gnu/14.3.0/liblto_plugin.so: error loading plugin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /nix/store/qdknxw57cwy1jkrhq7fzmiis73j42jv6-gcc-14.3.0/libexec/gcc/x86_64-unknown-linux-gnu/14.3.0/liblto_plugin.so)
collect2: error: ld returned 1 exit status
/tmp/dummy-flox-env/.flox/run/x86_64-linux.dummy-flox-env.dev/bin/gcc CMakeFiles/cmTC_43c1d.dir/testCCompiler.c.o -o cmTC_43c1d
make[1]: *** [CMakeFiles/cmTC_43c1d.dir/build.make:102: cmTC_43c1d] Error 1
make[1]: Leaving directory '/tmp/dummy-flox-env/build/CMakeFiles/CMakeScratch/TryCompile-hBSabD'
make: *** [Makefile:134: cmTC_43c1d/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!