Closed s1syph0s closed 4 weeks ago
Hi,
Clangd isn't able to query iccarm
for include paths, since it doesn't use the same command-line interface as clang. In your logs, we can see clangd trying and failing to invoke iccarm
with clang-style arguments:
"E[15:02:17.011] System include extraction: driver execution failed with return code: 2 - ''. Args: [\"C:\\\\PROGRA~1\\\\IARSYS~1\\\\EMBEDD~1.2\\\\arm\\\\bin\\\\iccarm.exe\" -E -v -x c -]
I believe the best way to achieve what you want is to remove the --query-driver
argument from clangd, and manually specify the system include paths in your .clangd file, for example:
CompileFlags:
Remove: [--silent]
Add:
- "-isystem"
- "C:/path/to/ewarm/arm/inc/"
- "-isystem"
- "C:/path/to/ewarm/arm/inc/c"
- "-isystem"
- "C:/path/to/ewarm/arm/inc/c/aarch32"
Please let me know whether that works for you!
Future versions of Embedded Workbench may include a command-line utility for generating clangd-compatible compile_commands.json
files, which would spare you the trouble of doing this manually.
Thank you for the help! iccarm
has an extension over the C language which clang might not understand and gives an error (The arm include oftentimes use this and i receive many errors). How would you overcome this problem?
It depends on the specific extension. For most keywords, like __root
, you can simply add a preprocessor define to "remove" them in your .clangd file:
CompileFlags:
Add:
- "-D__root="
Intrinsic functions can be treated similarly:
CompileFlags:
Add:
- "-D__section_begin(...)=((void*)0)"
Other extensions are trickier to handle, most notably the @
operator which is used in lots of device- and vendor-specific headers. Technically, you can fix these by rewriting them using #pragma location
instead, but it would be a lot of work and we can't recommend modifying system headers.
As I mentioned in my last post, we've been looking at improving clangd compatibility, and handling IAR compiler extensions is one of the things we've addressed. When this is released, Embedded Workbench will come with a custom version of clangd which is able to handle most IAR compiler extensions.
I wonder how VSCode handles it so properly. I too work with the same setup as OP and after compiling with CMake, I have 0 errors on VSCode. Doesn't it also use clangd as it's C++ LSP, or it uses something else?
VSCode's C/C++ extension uses Microsoft's proprietary IntelliSense engine. It doesn't support IAR language extensions either (there is a feature request for it here: https://github.com/microsoft/vscode-cpptools/issues/7653). Their engine is a bit more fault-tolerant in this case, and IIRC it sometimes hides parsing errors in system headers. However, if you try to use a symbol that is defined with the @
operator, you'll usually see an error in VS Code too.
Thanks for the explanation, and indeed some files that uses the @ operator have an error, I missed that. Any estimation of when we could have a iccarm version full compatible with clangd?
Unfortunately no, that is out of my hands. If you want an estimate, I'd suggest you contact IAR support to ask about it.
This issue is stale because it has been open for 30 days with no activity. If there is no further activity, the ticket will be automatically closed in 14 days.
This issue was closed because it has been inactive for 14 days since being marked as stale.
Hi, I'm wondering if the
iccarm
compiler is compatible to be read fromclangd
LSP? When using cmake, we can create thecompile_commands.json
and use this for theclangd
. I am trying to solve this problem by whitelisting theiccarm
compiler to query using--query-driver=
forclangd
, but I still can't get my LSP to correctly work...clangd file:
clangd is executed using this command:
stdio should not be pointing to visual studio, instead it should point to the header files from
iccarm
.clangd log: