cmake Test and Debug General approach to debug when building with Make


Example

Suppose the make fails:

$ make

Launch it instead with make VERBOSE=1 to see the commands executed. Then directly run the linker or compiler command that you'll see. Try to make it work by adding necessary flags or libraries.

Then figure out what to change, so CMake itself can pass correct arguments to the compiler/linker command:

  • what to change in the system (what libraries to install, which versions, versions of CMake itself)
  • if previous fails, what environment variables to set or parameters to pass to CMake
  • otherwise, what to change in the CMakeLists.txt of the project or the library detection scripts like FindSomeLib.cmake

To help in that, add message(${MY_VARIABLE}) calls into CMakeLists.txt or *.cmake to debug variables that you want to inspect.