Your comment got me down the right path. Setting the
-lgcov on the linker breaks, but setting
--coverage fixes the issue.
pio test -e native -vvv I got the commandlines for compiling and linking the code. I see that my compile commands have the
--coverage when compiling, but not when linking; and the
-lgcov option is only passed to the linker. So somewhere platformio is splitting up the build flags.
Looking up the docs for
--coverage for gnu:
The option is a synonym for -fprofile-arcs -ftest-coverage (when compiling) and -lgcov (when linking) source. So this behavior
platformio should be fine for gnu.
Now, digging through docs, I could not find docs for what this does on OS X.
On OS X,
clang. I couldn’t find any docs about
clang other than
Apple clang version 14.0.0 (clang-1400.0.29.202)
So I compared commandlines which are generated by g++/clang when we have
--coverage and when we do not by running
-v. On OS X, when we have the
--coverage option specified in a linker command, it adds this library to the ultimate commandline:
tldr; I believe the
--coverage option needs to be passed to the linker if the libraries are compiled with
--coverage. Using just
--coverage and not
-lgcov will make this platform independent as
--coverage is synonymous with
-lgcov on gnu, but will be handled correctly by clang (at least on OS X).
I should clarify. I am referring to the final program link
g++ -o .pio/build/native/program ... needs the
--coverage option. I need a way to force an option into this command to move forward.