Debugging native code: CMake C CPP JNI


A few tricks I found when building native code (C / C++ / JNI) with CMake.

Show exact build command

$ make VERBOSE=1 <target>

Diagnosis intermediate file

For each .c / .cpp file, there are intermediate files created from them:

  • .i: preprocessed source files (#define #include
  • .s: assembly code MOV INC ADD etc
  • .o: object file (machine code for target platform)

Normally they just reside in compiler memory and are not written to disk. In case we need to diagnose them, we can use Makefile targets generated by CMake.

Example: for console.test71.cxx in source set:

$ make console/test71.cxx.i

$ make console/test71.cxx.s

$ make console/test71.cxx.o