I'm aware there are some questions just like this one out there, but I wasn't able to get any value out of them (bc there's probably something I'm missing here).
I'm trying to set up intellisense in VScode to work with the rp2040 (pico). I am already able to build the project with cmake which was the first huge wall I was struggling to get across, but I'm now having difficulties trying to set up the intellisense to work just like it would with a normal C/C++ file when using VScode, but I can't get it to find or recognize the libraries in the pico-sdk directory, even if pointing directly at it (like giving it the exact path to the .h and .c files)
{
"configurations": [
{
"name": "RP2040",
"includePath": [
"${workspaceFolder}/**",
"C:/Users/Julio/VSARM/sdk/pico/pico-sdk/src/**",
"${env:PICO_SDK_PATH}/**",
"${workspaceFolder}/build/pico-sdk/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22000.0",
"compilerPath": "C:/Users/Julio/VSARM/armcc/10 2021.10/bin/arm-none-eabi-gcc.exe",
"intelliSenseMode": "gcc-arm",
"cStandard": "c11",
"cppStandard": "c++17",
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}
That's what's inside my c_cpp_properties.json file for this project, I attempted various calls to what I used to believe was the location of the libraries, but maybe I misunderstood that as well because it doesn't seem to care. "${workspaceFolder}/build/pico-sdk/**" is there because when I build with cmake it creates a pico-sdk folder inside the build folder as well, so I thought maybe doing that would work, but it didn't.
cmake_minimum_required(VERSION 3.12)
# Pull in SDK (must be before project)
include(pico_sdk_import.cmake)
project(blink C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
# Initialize the SDK and include the libraries
pico_sdk_init()
# Tell CMake where to find the executable source file
add_executable(${PROJECT_NAME}
main.c
)
# Create map/bin/hex/uf2 files
pico_add_extra_outputs(${PROJECT_NAME})
# Link to pico_stdlib (gpio, time, etc. functions)
target_link_libraries(${PROJECT_NAME}
pico_stdlib
)
# Enable usb output, disable uart output
pico_enable_stdio_usb(${PROJECT_NAME} 1)
pico_enable_stdio_uart(${PROJECT_NAME} 0)
add_compile_options(-Wall
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-unused-function # we have some for the docs that aren't called
-Wno-maybe-uninitialized
)
That's the content of my CMakeLists.txt just in case it's important to know. Is there maybe a way to make VScode intellisense work with CMake? Perhaps that could work better I don't know. I know for a fact the project builds successfully because I uploaded the file to the MCU and it works just fine, it's more of a VScode problem I think rather than CMake(?
UPDATE: I was able to get intellisense to detect the libraries for the Pico before actually trying to set CMake to be the intellisense provider as I was advised to do. The problem with that is that I'm not really sure how I managed it, I opened an unrelated cpp project in parallel to the RP2040 project and some automatic configuration from one of the extensions kicked in and fixed it. I assume this is a bad practice since I'm not aware of the reason why it works now. So I'm going to try the CMake way in short regardless.
Related
At some point in the last year (because it was working at some point), the Visual Studio Code setup I use to edit a firmware project based on Zephyr ( https://zephyrproject.org/ - the actual project is the ZMK keyboard firmware https://zmkfirmware.dev/ ) stopped presenting me with code completion options, the ability to "Go to Definition/Go to Declaration", etc - I definitely had these working at some point, then they stopped. I noticed it a while ago, but it hasn't been high enough priority to fix.
Unfortunately, like a lot of modern software, the settings which affect this seem to be scattered over a lot of different places, and it's not really clear to me where they all are and how they should be set. I have the C/C++ extension installed, as well as the "C/C++ extension pack", because the primary language in use is C.
On my primary repository (the one under active development), I see "Loading..." indefinitely when I hover over things in a C window. If I check out a completely new project (from the ZMK github repo), I see errors because certain #include files (like #include <kernel.h>) can't find other files included within - I assume because some paths are not set properly. I vaguely recall setting some include paths once upon a time in my main repo, but I can't find those settings now. (see "scattered over a lot of different places", above)
The main difference in the .vscode dir between the two seems to be that the eternally "Loading" one has .vscode/c_cpp_properties.json and the one that gives errors does not. Here's what's in the file:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [],
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "${default}",
"compilerPath": "/usr/local/bin/arm-none-eabi-gcc",
"compileCommands": "${workspaceFolder}/app/build/compile_commands.json"
}
],
"version": 4
}
So, questions:
how do I see what error is being encountered when "Loading..." never goes away?
what can I do to fix this problem on MacOS?
where do I configure the include paths that Intellisense uses for include files to find their further includes?
is there a list of all the different places things can be configured in VSCode, and what they are?!?
Suddenly, "make" has stopped working: did not generate *.so php extension;
gcc has stopped working: did not find header files;
Visual studio code started showing problems: headers missing.
I have reinstalled: glibc, libc6-dev, build-essentials, gcc-multilib, and g++-multilib.
I have reinstalled Visual Studio Code for Linux Mint.
I have added the paths to configuration.json of Visual Studio ( settings-> search for c_cpp_confiuration.json or similar, or under settings-> c/c++ extensions ->configuration file )
{
"window.zoomLevel": -3,
"workbench.colorTheme": "Visual Studio Light - C++",
"editor.minimap.enabled": false,
"files.autoSave": "afterDelay",
"C_Cpp.default.browse.path": [],
"C_Cpp.default.compilerPath": "",
"C_Cpp.default.customConfigurationVariables": {},
"C_Cpp.default.defines": [],
"C_Cpp.default.includePath": [ "/usr/lib/gcc/x86_64-linux-gnu/9/include", "/usr/include", "usr/local/include", "/usr/include/php/20190902", "/usr/include/php/20190902/main", "/usr/include/php/20190902/Zend", "/usr/include/php/20190902/TSRM", "${workspaceRoot}", "$(VC_IncludePath)", "$(UniversalCRT_IncludePath)" ]
}
I have added the environmental variable C_INCLUDE_PATH to
#/etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/drb/lampstack-7.4.11-0/.symfony/bin:/drb/lampstack-7.4.11-0/php/bin:";
C_INCLUDE_PATH="/usr/lib/gcc/x86_64-linux-gnu/9/include:/usr/include:usr/local/include:/usr/include/php/20190902:/usr/include/php/20190902/main:/usr/include/php/20190902/Zend:/usr/include/php/20190902/TSRM:"
I have rebooted the computer.
Visual Studio does not show problems.
But make does not work ( does not show any errors, but does not produce php-extension.lo and *.la),
sudo make install does not work ( does not show any errors, but does not produce php-extension.so )
and gcc can not find header files.
made a simple shell script to set C_INCLUDE_PATH from project folder
#env.sh
#!/bin/bash
C_INCLUDE_PATH="/usr/lib/gcc/x86_64-linux-gnu/9/include:/usr/include:usr/local/include:/usr/include/php/20190902:/usr/include/php/20190902/main:/usr/include/php/20190902/Zend:/usr/include/php/20190902/TSRM:"
export C_INCLUDE_PATH
CPATH="/usr/lib/gcc/x86_64-linux-gnu/9/include:/usr/include:usr/local/include:/usr/include/php/20190902:/usr/include/php/20190902/main:/usr/include/php/20190902/Zend:/usr/include/php/20190902/TSRM:"
export CPATH
echo "set C_INCLUDE_PATH to"
printenv C_INCLUDE_PATH
but make does not work and gcc does not find headers.
Trying to set from command line
$ gcc -I "usr/include/php/201990902:/usr/include/php/20190902/main" tsub76.c
gives the same fatal error that header does not exist. Checking folder, the header exists as /usr/include/php/20190902/main/php.h
Where are the configuration files of gcc and make located to to set include path for headers ?
The reason is a some error in php extension code, like error in variable name, like 72 instead of 76 in
zend_function_entry tsub72_functions[] = {...
instead of zend_function_entry tsub76_functions[] = {...
( not sure in which places, and how many occurrences )
A simple_file.c including any of headers is working.
gcc simple_file.c -lm -g
Does not work only the extension.c, which i can not show, it is not public.
But, if somebody know the file name where it is set the make and gcc configuration variables setting headers include paths, could you please write me.
I'm working in VSCode with the C/C++ extension on Ubuntu 18.04.
I'm trying to include gmodule.h and it raises the error gmodule.h: No such file or directory on line 2, character 10 of the main file.
So, the problem lies with gmodule.h being not in /usr/include but in /usr/include/glib-2.0. Realizing this, I added this folder to the includePath variable in c_cpp_properties.json. However, it still raises the same error.
When using #include <glib-2.0/gmodule.h> instead of #include <gmodule.h>, it does work but this only shifts the problem to gmodule.h itself, as other includes that lie in the glib-2.0 folder still don't work inside of gmodule.h.
All in all, the problem is that add to the includePath in c_cpp_properties.json doesn't change anything and I want to know how to make this work, since I would like to use gmodule.
c_cpp_properties.json:
{
"configurations": [
{
"name": "Linux",
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"includePath": [
"/usr/include/glib-2.0/*"
]
}
],
"version": 4
}
for now I'm just trying to include gmodule.h and not do anything with it yet, so this is my main file:
#include <stdio.h>
#include <gmodule.h>
int main() {
printf("hai\n");
return 0;
}
The c_cpp_properties.json controls, among other things, where intellisense in the IDE resolves include files. The IDE and the build tasks are independent things and as a result, configured and operate independently in VS Code.
The solution to your problem is to add the include path to your tasks.json file, as follows:
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"--include-directory=/usr/include/glib-2.0/"
],
I managed to make IntelliSense work by adding two paths for glib as reported by pkg-config:
$ pkg-config --cflags glib-2.0
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
.vscode/c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/glib-2.0/**",
"/usr/lib/x86_64-linux-gnu/glib-2.0/include/**"
],
"defines": [],
...
}
],
...
}
I had the same issue, and it was caused by the configurationProvider option in the c_cpp_properties.json file pointing to a disabled makefile-tools plugin. The makefile-tools plugin was correctly generating the list of include paths, but these paths were not included in the final list of include paths for Intellisense, because the plugin was disabled. In my case, the solution was either remove that configuration option or enable the makefile-tools plugin.
What solved it for me was to just type folder path without /* or /**
Then it prompted me if I want to enable Intellisense for this folder and I allowed it and it worked.
Issue:
Thanks all! This pointed me in the right directions. I was getting an error not finding the WxWidgets library. The "configurationProvider" issue seems to be the problem.
I do have "makefile-tools" installed and the "configurationProvider" pointed to it, so not sure why there was an issue.
For this solution, I also had tried forcing the include directories in the "includePath" with no success as per the original issue.
My project is using CMake, but the "configurationProvider" was pointing to "makefile-tools" for whatever reason. I removed the forced "includePath" paths and pointed "configurationProvider" to "ms-vscode.cmake-tools". This seemed to fix my issue after reopening the project.
Solution:
ctrl-shift-p
C/C++: Change Configuration Provider...
Select "CMake Tools"
Exit VSCode
Start VSCode
Currently I am using Clion IDE plus latest version of Open Watcom v2 windows 32 bit compiler to develop some 16 bit MS-DOS application. The problem I have is I don't see all required debugging information when using watcom windows debugger (wdw.exe).
Being specific, I see global variables, global and any other types of functions, even those imported from asm files. But well, local variables list is empty all the time. But more importantly - the only c-code I can see is little test.c file which contains only main() function and nothing else except for includes.
What do I need to do to finally get c-level debugging for whole project? What am I missing?
I would be grateful for any help.
All source files is located in one directory, so, they all should be visible to debugger. But it sees only main c file.
Of course I am compiling with -d2 switch, as well as -hw. DEBUG WATCOM ALL is also presented in linker config file before any FILE directives. Reading manuals to compiler and linker... Well, it's nice that I've found many interesting things in manuals, but nothing helped with exactly that issue so far :)
List of compiler switches I currently using:
WCC.EXE:
CALL WCC.EXE -dTEST -bt=dos -0 -za99 -wx -we -mc -zp2 -hw -d2
%SRC_FULL_NAME%
WLINK:
CALL WLINK.EXE #..\CC.LK
CC.LK:
SYSTEM DOS
DEBUG WATCOM ALL
FILE TEST.OBJ
FILE LUTILS.OBJ
FILE LGL.OBJ
NAME TEST.EXE
OPTION ELIMINATE
...
I've already got Vim with YouCompleteMe plugin (compiled with semantic support for C-family languages), which I use for Python etc. Now I'd like to try it with C (I've never developed with C before, so I've got a slightly fuzzy idea about some details, like the necessary flags.)
To use YCM's semantic completion features with C, I need to provide it a .ycm_extra_conf.py file; the YCM user guide points to YCM's own .ycm_extra_conf.py as a reference (link).
Would the following (based on the aforesaid .ycm_extra_conf.py) produce "a minimal working setup" for C (to which I could then point g:ycm_global_ycm_extra_conf):
The flags:
flags = [
'-Wall', '-Wextra', '-Werror',
'-std=c11',
'-x', 'c'
]
and FlagsForFile function without the final_flags.remove( '-stdlib=libc++' ) line.
Otherwise the example file would remain as-it-is. I believe that -isystem flags are strictly YCM-related, is that correct?
I was searching for this too and seems here we haven't get a good solution. Even this is a very old question I hope this might help someone. The following works for me,
import os
import ycm_core
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-Wno-long-long',
'-Wno-variadic-macros',
'-fexceptions',
'-ferror-limit=10000',
'-DNDEBUG',
'-std=c99',
'-xc',
'-isystem/usr/include/',
]
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', ]
def FlagsForFile( filename, **kwargs ):
return {
'flags': flags,
'do_cache': True
}
By the way, that long config file by the default bothers me so much. I should give credit for this post, http://cocoaspice.logdown.com/posts/302432-youcompleteme-toss-notes
Nothing at all is perfectly valid as long as the sources can be compiled by simply clang++ -c source (c vs. c++ is decided from extension). YCM happily completes in scratch tests created in random directories for me.
The -x c is not needed. If the source has extension .c or .h, it is assumed to be C and if it has extension .C, .cc, .cpp, .cxx, .H, .hh, .hpp or .hxx it is assumed C++. Only if you have C++ headers with just .h you need -x c++-header.
Newest clang (4.9) already defaults to c11 and c++11, so you shouldn't need those either.
So you only need any -I flags and the warnings are useful.
To give you a working example, here is the configuration I'm using for Arduino projects.
https://github.com/WeAreLeka/Bare-Arduino-Project/blob/master/.ycm_extra_conf.py
In the flags I've put all the Arduino libraries provided by the IDE and needed to compile my code.
I've also written a little function to find the other libraries in my /lib dir that I'm using in my project and to add them automatically to flags. It's line 57.
It's helpful if you use a lot of libs and don't want to modify your conf file each time.
Without the -I /path/to/lib/folder you won't get autocompletion.
Hope this helps :)