Skip to content

Troubleshooting

Lars Melchior edited this page Apr 21, 2020 · 2 revisions

Troubleshooting

Some help to frequent problems that may arise.

How to use a newer gcc version in the tests

The tests use the default gcc available on the current platform (as it's a good way to ensure compatibility with common build systems), but you can override it to use another version. Currently, ubuntu-latest seems to support at least gcc-9. If you want to use that, you can change your action accordingly.

    - name: configure
      run: CXX=g++-9 cmake -Htest -Bbuild -DENABLE_TEST_COVERAGE=1

Be sure to also use the correct version of gcov.

    - name: collect code coverage
      run: bash <(curl -s https://codecov.io/bash) -x gcov-9 || echo "Codecov did not collect coverage reports"

How to create a header-only library

The library type has to be changed to an interface library and all operations on the library must have INTERFACE scope. See here for an example.

I cannot see headers of my header-only library in the IDE

Then you might want to create an extra target only for the headers.

add_library(MyLibraryHeaders EXCLUDE_FROM_ALL ${headers})
set_target_properties(MyLibraryHeaders PROPERTIES LINKER_LANGUAGE CXX)

The install test fails because of missing dependencies

Always pass all dependencies to PackageProject.cmake so CMake will look for them when adding the library. See here for an example.

My test coverage is not accurate

For template heavy libraries the default settings of codecov might not not work accurately. In that case it can make sense to manually collect the coverage data. Note that the versions of gcc and gcov must be compatible. See here for an example workflow.