Skip to content

CDT fails to generate correct commands in compile_commands.json file #1130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dc42 opened this issue Apr 8, 2025 · 1 comment · May be fixed by #1138
Open

CDT fails to generate correct commands in compile_commands.json file #1130

dc42 opened this issue Apr 8, 2025 · 1 comment · May be fixed by #1138

Comments

@dc42
Copy link

dc42 commented Apr 8, 2025

Using Eclipse CDT 4.35.0 (build ID 20250306-0812) under Windows, cross compiling for ARM gcc. When the LSP editor is selected and logging is enabled, the output in the console window is as follows:

I[14:59:50.488] clangd version 18.1.8
I[14:59:50.488] Features: windows
I[14:59:50.488] PID: 36888
I[14:59:50.488] Working directory: C:\Users\David\eclipse\cpp-2024-06\eclipse
I[14:59:50.488] argv[0]: C:\Program Files\LLVM\bin\clangd.exe
I[14:59:50.488] argv[1]: --clang-tidy
I[14:59:50.488] argv[2]: --background-index
I[14:59:50.488] argv[3]: --completion-style=detailed
I[14:59:50.488] argv[4]: --pretty
I[14:59:50.488] argv[5]: --query-driver=C:\Program Files (x86)\Arm GNU Toolchain arm-none-eabi\13.2 Rel1\bin\*g++.exe,C:\Program Files (x86)\Arm GNU Toolchain arm-none-eabi\13.2 Rel1\bin\*gcc.exe
I[14:59:50.488] argv[6]: --function-arg-placeholders=1
I[14:59:50.493] Starting LSP over stdin/stdout
I[14:59:50.938] <-- initialize("1")
I[14:59:50.941] --> reply:initialize("1") 2 ms
I[14:59:51.018] <-- initialized
I[14:59:51.033] <-- textDocument/didOpen
I[14:59:51.036] --> textDocument/publishDiagnostics
I[14:59:51.036] <-- textDocument/documentLink("2")
I[14:59:51.036] Loaded compilation database from C:\Eclipse\Firmware-3.6\RRFLibraries\SAME70_RTOS\compile_commands.json
I[14:59:51.036] <-- textDocument/semanticTokens/full("3")
I[14:59:51.038] --> window/workDoneProgress/create(0)
I[14:59:51.038] Enqueueing 43 commands for indexing
I[14:59:51.042] <-- textDocument/inlayHint("4")
E[14:59:51.042] System include extraction: driver arm-none-eabi- not found in PATH
I[14:59:51.046] ASTWorker building file C:\Eclipse\Firmware-3.6\RRFLibraries\src\General\SimpleMath.cpp version 1 with command 
[C:/Eclipse/Firmware-3.6/RRFLibraries]
"C:\\Program Files\\LLVM\\bin\\arm-none-eabi-" -std=gnu++17 -D__SAME70Q21__ -DRTOS "-IC:\\Eclipse\\Firmware-3.6\\FreeRTOS\\src\\include" "-IC:\\Eclipse\\Firmware-3.6\\FreeRTOS\\src\\portable\\GCC\\ARM_CM7\\r0p1" -O2 -Wall -c -mcpu=cortex-m7 -mthumb -fno-math-errno -mfpu=fpv5-d16 -mfloat-abi=hard -mfp16-format=ieee -mno-unaligned-access -ffunction-sections -fdata-sections -fno-threadsafe-statics -fno-rtti -fno-exceptions -nostdlib -Wundef -Wdouble-promotion -fsingle-precision-constant -Wa,-ahl=$*.s -o C:/Eclipse/Firmware-3.6/RRFLibraries/SAME70_RTOS/src/General/SimpleMath.o "-resource-dir=C:\\Program Files\\LLVM\\lib\\clang\\18" -- "C:\\Eclipse\\Firmware-3.6\\RRFLibraries\\src\\General\\SimpleMath.cpp"
I[14:59:51.060] <-- reply(0)
I[14:59:51.060] --> $/progress
I[14:59:51.060] --> $/progress
I[14:59:51.094] --> textDocument/publishDiagnostics
I[14:59:51.095] Loaded compilation database from C:\Eclipse\Firmware-3.6\FreeRTOS\SAME51\compile_commands.json
I[14:59:51.161] --> $/progress
I[14:59:51.161] --> $/progress
I[14:59:51.161] --> $/progress
I[14:59:51.161] --> $/progress
I[14:59:51.161] --> $/progress
I[14:59:51.161] --> $/progress
I[14:59:51.161] --> $/progress
I[14:59:51.161] --> $/progress
I[14:59:51.161] --> $/progress
I[14:59:51.161] --> $/progress
I[14:59:51.161] --> $/progress
I[14:59:51.162] --> $/progress
I[14:59:51.162] --> $/progress
I[14:59:51.162] --> $/progress
I[14:59:51.162] --> $/progress
I[14:59:51.162] --> $/progress
I[14:59:51.162] --> $/progress
I[14:59:51.162] --> $/progress
E[14:59:51.172] System include extraction: driver m-none-eabi- not found in PATH
E[14:59:51.172] System include extraction: driver m-none-eabi- not found in PATH
E[14:59:51.172] System include extraction: driver m-none-eabi- not found in PATH
E[14:59:51.172] System include extraction: driver m-none-eabi- not found in PATH
E[14:59:51.172] System include extraction: driver m-none-eabi- not found in PATH
E[14:59:51.172] System include extraction: driver m-none-eabi- not found in PATH
...

The errors appear to be because the compile_commands.json file does not contain the G++ or GCC command, just the prefix. Here is the start of compile_commands.json:

[
  {
    "directory": "C:/Eclipse/Firmware-3.6/RepRapFirmware",
    "command": "arm-none-eabi- -std\u003dgnu++17 -D__SAME70Q20B__ -DRTOS -DDUET3_MB6HC -DMQTTC_PAL_FILE\u003d\"Networking/MQTT/mqtt_pal.h\" -D_XOPEN_SOURCE -I\"C:\\Eclipse\\Firmware-3.6\\LibTinyusb\" -I\"C:\\Eclipse\\Firmware-3.6\\CoreN2G\" -I\"C:\\Eclipse\\Firmware-3.6\\FreeRTOS\" -I\"C:\\Eclipse\\Firmware-3.6\\CoreN2G\\src\" -I\"C:\\Eclipse\\Firmware-3.6\\CoreN2G\\src\\SAM4S_4E_E70\" -I\"C:\\Eclipse\\Firmware-3.6\\CoreN2G\\src\\SAM4S_4E_E70\\asf\\common\\utils\" -I\"C:\\Eclipse\\Firmware-3.6\\CoreN2G\\src\\SAM4S_4E_E70\\asf\\sam\\utils\\cmsis\\same70\\include\" -I\"C:\\Eclipse\\Firmware-3.6\\CoreN2G\\src\\arm\\CMSIS\\5.4.0\\CMSIS\\Core\\Include\" -I\"C:\\Eclipse\\Firmware-3.6\\CoreN2G\\src\\SAM4S_4E_E70\\SAME70\" -I\"C:\\Eclipse\\Firmware-3.6\\CoreN2G\\src\\SAM4S_4E_E70\\asf\" -I\"C:\\Eclipse\\Firmware-3.6\\CoreN2G\\src\\SAM4S_4E_E70\\asf\\sam\\utils\" -I\"C:\\Eclipse\\Firmware-3.6\\CoreN2G\\src\\SAM4S_4E_E70\\asf\\sam\\utils\\preprocessor\" -I\"C:\\Eclipse\\Firmware-3.6\\CoreN2G\\src\\SAM4S_4E_E70\\asf\\sam\\utils\\header_files\" -I\"C:\\Eclipse\\Firmware-3.6\\CoreN2G\\src\\SAM4S_4E_E70\\asf\\sam\\drivers\" -I\"C:\\Eclipse\\Firmware-3.6\\RepRapFirmware\\src\" -I\"C:\\Eclipse\\Firmware-3.6\\RepRapFirmware\\src\\Hardware\\SAME70\" -I\"C:\\Eclipse\\Firmware-3.6\\RepRapFirmware\\src\\Networking\" -I\"C:\\Eclipse\\Firmware-3.6\\RepRapFirmware\\src\\Networking\\LwipEthernet\\Lwip\" -I\"C:\\Eclipse\\Firmware-3.6\\RepRapFirmware\\src\\Networking\\LwipEthernet\\Lwip\\src\\include\" -I\"C:\\Eclipse\\Firmware-3.6\\RepRapFirmware\\src\\Networking\\MQTT\\MQTT_C\\include\" -I\"C:\\Eclipse\\Firmware-3.6\\WiFiSocketServerRTOS\\src\\include\" -I\"C:\\Eclipse\\Firmware-3.6\\FreeRTOS\\src\\include\" -I\"C:\\Eclipse\\Firmware-3.6\\FreeRTOS\\src\\portable\\GCC\\ARM_CM7\\r0p1\" -I\"C:\\Eclipse\\Firmware-3.6\\RRFLibraries\\src\" -I\"C:\\Eclipse\\Firmware-3.6\\CANlib\\src\" -O2 -Wall -c -mcpu\u003dcortex-m7 -mthumb -fno-math-errno -mfpu\u003dfpv5-d16 -mfloat-abi\u003dhard -mfp16-format\u003dieee -mno-unaligned-access -ffunction-sections -fdata-sections -fno-threadsafe-statics -fno-rtti -fexceptions -nostdlib -Wundef -Wdouble-promotion -Werror\u003dreturn-type -Wsuggest-override -fsingle-precision-constant \"-Wa,-ahl\u003d$*.s\" -fstack-usage -o \"C:/Eclipse/Firmware-3.6/RepRapFirmware/Duet3_MB6HC/src/Accelerometers/Accelerometers.o\" \"C:/Eclipse/Firmware-3.6/RepRapFirmware/src/Accelerometers/Accelerometers.cpp\"",
    "file": "C:/Eclipse/Firmware-3.6/RepRapFirmware/src/Accelerometers/Accelerometers.cpp"
  },
  {

This is the tools setup I am using:

Image

where ArmGccPath is a build variable containing the path to the version of gcc that this workspace uses, for example:

Image

The .cproject file is available at https://github.com/Duet3D/RepRapFirmware/blob/3.6-dev/.cproject. The make utility in use is the one provided by MSYS2.

@jonahgraham
Copy link
Member

@Kummallinen / @alicetrifu can you have a look at this issue please?

I can't reproduce exactly what @dc42 has, but on Linux, creating a C project with a cross-compile toolchain leads me to a compile commands.json with:

"command": "\"/usr/bin/gcc\" arm-none-eabi- -O0 -g3 -Wall...

AFAICT if you don't have gcc on your PATH you get what @dc42 reports.

The error comes from an error introduced in #824 when full command lines were added. The assumption was that the ITool described the full toolname, but when using cross gcc, the IManagedCommandLineGenerator modifies the command by adding the prefix. i.e. ITool.getToolCommand returns gcc, but CrossCommandLineGenerator modifies it to be arm-none-eabi-gcc.

The problem can be seen here:

String compilerName = CompilationDatabaseGenerator.getCompilerName(tool);
String commandLine = cmdLInfo.getCommandLine();
commandLine = commandLine.replace(compilerName, "").trim(); //$NON-NLS-1$

commandLine has the correct value, but not an absolute path. However compilerName has the non-prefixed value (e.g. just gcc) so the commandLine.replace call changes arm-none-eabi-gcc to arm-none-eabi-. The following lines then try to find the full path of gcc, instead of the prefixed arm-none-eabi-gcc leading to the wrong result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants