5

I would like to investigate why I have this error:

$ cmake ..
-- The C compiler identification is unknown
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /cygdrive/c/Users/Ycr/Home/bin/arm-none-eabi-gcc
-- Check for working C compiler: /cygdrive/c/Users/Ycr/Home/bin/arm-none-eabi-gcc -- broken
CMake Error at /usr/share/cmake-3.6.2/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "/cygdrive/c/Users/Ycr/Home/bin/arm-none-eabi-gcc" is not
  able to compile a simple test program.

Unfortunately after the error:

  • I have no idea of what CMake did. I don't have a verbose log of the command it executed.
  • The CMakeFiles/cmTC_e4aa4.dir was cleaned after the error, so I have no possibility to explore the issue myself.

How should I investigate such an error?

I tried to use the --debug-trycompile option. This time CMake creates a CMakeTmp folder which makes perfectly without errors. However, I still have this CMakeFiles/cmTC_e4aa4.dir that generates errors and even with the option CMake unlinks the folder.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nowox
  • 25,978
  • 39
  • 143
  • 293
  • Possible duplicate of [CMake, how to keep generated temporary files?](https://stackoverflow.com/questions/38115842/cmake-how-to-keep-generated-temporary-files) And take a look at `CMakeFiles\CMakeError.log` and check the error message there. – Florian Aug 24 '17 at 11:11
  • Doesn't really work, the `CMakeFiles/cmTC_53a28.dir/build.make` is not there anymore... With the `--debug-trycompile` I get a `CMakeTmp` file which builds without errors. – nowox Aug 24 '17 at 11:24
  • Strange. What does `CMakeError.log` say? Looking at your error message again, that compiler won't work without a [toolchain file](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html) or switching to static library linking (it won't compile an executable). For a solution see e.g. [How to partially disabling cmake C/C++ custom compiler checking](https://stackoverflow.com/questions/38700198/how-to-partially-disabling-cmake-c-c-custom-compiler-checking). – Florian Aug 24 '17 at 11:37
  • I get this: https://gist.github.com/nowox/e90b768126d3e2a8b49fb759505e55c0 – nowox Aug 24 '17 at 11:43
  • My problem is not really the output, but the input. I just would like to see what commands it executes. I feel this is a very simple request that CMake should be able to do. – nowox Aug 24 '17 at 11:44
  • Have a look at https://stackoverflow.com/q/38864489/2799037 and https://stackoverflow.com/q/22803607/2799037 – usr1234567 Aug 24 '17 at 12:22
  • @nowox The error is in your error log: "undefined reference to `_exit'". So see [here](https://stackoverflow.com/questions/19419782/exit-c-text0x18-undefined-reference-to-exit-when-using-arm-none-eabi-gcc) and [here](https://stackoverflow.com/questions/33053840/converting-a-makefile-to-cmakelists-txt-for-tiva-c-series). – Florian Aug 24 '17 at 12:30
  • I've seen it. My question is more where can I get the full log – nowox Aug 24 '17 at 12:45

2 Answers2

3

Getting a Verbose Log

The try_compile() calls that CMake does in the beginning to test the compiler, gives a detailed error output on the console and writes it to

[your binary output directory]/CMakeFiles/CMakeError.log

I've checked the source code again and there is no CMake option that would give more a more detailed output for CMake's internal try_compile() calls.

You could just force the output to standard output by adding some variable_watch() calls to your main CMakeLists.txt before your project() call like:

variable_watch(__CMAKE_C_COMPILER_OUTPUT)
variable_watch(__CMAKE_CXX_COMPILER_OUTPUT)

Keeping the Temporary Files

To keep the temporary file of try_compile, add --debug-trycompile to the cmake command line.

But be aware that the multiple compiler tests at the beginning overwrite the artifacts of previous ones:

It may however change the results of the try-compiles as old junk from a previous try-compile may cause a different test to either pass or fail incorrectly. This option is best used for one try-compile at a time, and only when debugging.

References

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Florian
  • 39,996
  • 9
  • 133
  • 149
1

For me, none of the log files in my output directory contained useful information from try_compile(), even when using --debug-trycompile.

I ended up using the OUTPUT_VARIABLE option to capture and then print the output like this:

try_compile(<options> OUTPUT_VARIABLE TRY_COMPILE_OUTPUT)

message(WARNING ${TRY_COMPILE_OUTPUT})
Frederik
  • 467
  • 6
  • 16