newlib not included in compile_commands.json for some files #1605

Closed
opened 2024-01-12 04:59:55 -06:00 by ast · 7 comments
ast commented 2024-01-12 04:59:55 -06:00 (Migrated from github.com)

I generated a cpp project named keyboard with pico-project-generator.

Using cmake 3.27.4 with

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

, to generate a compile_commands.json for use with clangd (in my case with eglot on emacs).

For the file `keyboard.cpp -I/usr/include/newlib is missing, but it's there for other files such is irq_handler_chain.S and most if not all other .S files.

This causes code completion not to work correctly.

I have been unable to find the cause of this, but worked around it using:

set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES /usr/include/newlib)

I generated a cpp project named keyboard with pico-project-generator. Using cmake 3.27.4 with `set(CMAKE_EXPORT_COMPILE_COMMANDS ON)` , to generate a compile_commands.json for use with clangd (in my case with eglot on emacs). For the file `keyboard.cpp -I/usr/include/newlib is missing, but it's there for other files such is irq_handler_chain.S and most if not all other .S files. This causes code completion not to work correctly. I have been unable to find the cause of this, but worked around it using: `set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES /usr/include/newlib)`
peterharperuk commented 2024-01-12 06:19:27 -06:00 (Migrated from github.com)

Why is your pico project using /usr/include/newlib?

Why is your pico project using /usr/include/newlib?
ast commented 2024-01-12 07:49:56 -06:00 (Migrated from github.com)

It's the standard C library used by pico-sdk.

For some reason Ubuntu installs the headers there. Is there a better way?

It's the standard C library used by pico-sdk. For some reason Ubuntu installs the headers there. Is there a better way?
vulpes2 commented 2024-02-08 11:08:37 -06:00 (Migrated from github.com)

Just ran into this, on a Fedora system you can set this to make clangd work:

set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES /usr/arm-none-eabi/include)
Just ran into this, on a Fedora system you can set this to make clangd work: ``` set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES /usr/arm-none-eabi/include) ```
will-v-pi commented 2024-08-09 11:20:00 -05:00 (Migrated from github.com)

There have been some changes to the way newlib is included in SDK 2.0.0, so could you try with the new SDK and see if this is still an issue?

There have been some changes to the way newlib is included in SDK 2.0.0, so could you try with the new SDK and see if this is still an issue?
vulpes2 commented 2024-08-10 14:22:41 -05:00 (Migrated from github.com)

Nothing has changed so far. Without set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES /usr/arm-none-eabi/include) things like stdio.h still cannot be found. Tested with the latest version of pico-sdk and pico-examples.

Nothing has changed so far. Without `set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES /usr/arm-none-eabi/include)` things like `stdio.h` still cannot be found. Tested with the latest version of `pico-sdk` and `pico-examples`.
will-v-pi commented 2024-08-21 10:09:58 -05:00 (Migrated from github.com)

Looking at the clangd docs, the best way to get it working seems to be to specify --query-driver on the command line with the path to your compiler, rather than specifying system include paths manually (https://clangd.llvm.org/troubleshooting#cant-find-standard-library-headers-map-stdioh-etc)

This works with pico examples, by generating compile_commands.json, and then running

clangd --query-driver=/usr/bin/* --check=hello_world/usb/hello_usb.c

for example - it now picks up the newlib headers correctly

The --query-driver argument is documented here

Looking at the clangd docs, the best way to get it working seems to be to specify `--query-driver` on the command line with the path to your compiler, rather than specifying system include paths manually (https://clangd.llvm.org/troubleshooting#cant-find-standard-library-headers-map-stdioh-etc) This works with pico examples, by generating compile_commands.json, and then running ``` clangd --query-driver=/usr/bin/* --check=hello_world/usb/hello_usb.c ``` for example - it now picks up the newlib headers correctly The `--query-driver` argument is documented [here](https://clangd.llvm.org/guides/system-headers#query-driver)
will-v-pi commented 2024-11-12 05:30:42 -06:00 (Migrated from github.com)

Closing this, as I don't think the newlib libraries should be included in compile_commands.json - instead the intellisense tool used (eg clangd) should query the compiler for the system library locations

Closing this, as I don't think the newlib libraries should be included in `compile_commands.json` - instead the intellisense tool used (eg `clangd`) should query the compiler for the system library locations
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#1605
No description provided.