How to configure Visual Studio Code includePath for Arduino and Teensy - c

I'm working with Arduino and Teensy boards from inside VS code. I can build and program everything fine, but the highlighting and code following functions built into VS Code don't work.
Previously, my custom headers weren't loading or highlighting, but this answer got that working for me. Now I have the right libraries on my include path (and I can click and follow them to the correct source) but some names still don't work:
My includePath appears to be configured correctly, as I mentioned I can follow the includes and it opens the correct sources:
"includePath": [
"${workspaceFolder}/**",
"C:/Program Files (x86)/Arduino/**",
"C:/Program Files (x86)/Arduino/hardware/teensy/avr/cores/teensy/**",
"C:/Program Files (x86)/Arduino/hardware/teensy/avr/libraries/ADC/**",
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/cores/arduino/**",
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/variants/standard/**",
"C:/Program Files (x86)/Arduino/hardware/tools/avr/lib/gcc/avr/5.4.0/include/**"
]
I can confirm the header is on the includePath and has the names defined I'm looking for:
Somehow VS Code is still saying the identifier is undefined.
Any ideas?

Just install the Arduino extension and run vscode command Arduino: initialize. You will need to select board and
File .vscode\c_cpp_properties.json and .vscode\arduino.json will automatically created.

Related

Unable to open header file in visual studio when compiling c-program

In the folder with all my C-files I include the headerfile pic32mx.h in my c-files
#include <pic32mx.h>
But when compiling any of those c-files I get the error
fatal error: 'pic32mx.h' file not found
I went into the json-file of the folder (called c_cpp_properties.json) to set the includePath for the headerfile like this (I added the second path):
"includePath": [
"${workspaceFolder}/**",
"/Applications/mcb32tools.app/Contents/Resources/Toolchain/include"
],
Yet I still get the error of not being able to compile the program, the header file is not found. I am running GCC on Mac OS and the IDEA is Visual Studio Code.

WebKit header file confusion

I've downloaded and installed WebKit (webkitgtk-2.26.1) on my Ubuntu 19.04 computer for use with C/GTK+, and I have an issue with the include files. All of the sample code I'm seeing includes the header files as #include <webkit2/webkit2.h>. But there is no webkit2 folder installed with WebKit, although all the header files in ~/Utils/WebKitGtk/webkitgtk-2.26.1/Source/WebKit/UIProcess/API/gtk/webkit2 refer to
#include <webkit2/*.h> as well. I don't think I want to start editing WebKit header files, so I'm hoping someone out there has run into this and can point me in the right direction.
you can try:
mkdir /usr/local/include/webkit2 or mkdir /usr/include/webkit2, then copy the header files into the directory.
or
configure C_INCLUDE_PATH=$C_INCLUDE_PATH:~/Utils/WebKitGtk/webkitgtk2.26.1/Source/WebKit/UIProcess/API/gtk/
you can refer to https://gcc.gnu.org/onlinedocs/cpp/Environment-Variables.html

CMake: Header files cannot be opened

I am working to build a Code Composer Studio project using cmake, which is new to me. It builds successfully under Linux but I am struggling to get it to work under Windows. The cmake command executes without issue, but make fails during the very first C object at the very first #include with the error code
fatal error: could not open source file "stdbool.h" (no directories in search list)
I'm using the libraries included in CCS's compiler (c6000_7.4.15), and that whole folder is included in the CSS project. I include it in cmake as well. In my .cmake file:
set (CCS_ROOT ${CCS_ROOT_V6_WIN} CACHE PATH "code composer install directory")
set(CGT_COMPILER_ROOT ${CCS_ROOT}/tools/compiler/c6000_7.4.15 CACHE INTERNAL "DSP Compiler Root")`
And in the CMakeLists.txt file:
set (COMPILER_INCLUDE ${CGT_COMPILER_ROOT}/include)
INCLUDE_DIRECTORIES ("${COMPILER_INCLUDE}")
Why can the header files not be opened when they're linked in the project and CMake can find them just fine?
EDIT: The directory structure had been changed underneath me, so I took the opportunity to add all of the external files directly into the project to make it completely platform-independent. That way, since the project is managed by our Git repository, users won't have to install the CSL or any other programs to build the project. This also means that paths to libraries and header files will never change between revisions and environments.
Unfortunately, this has not solved my problem. The project continues to build in Linux while failing to ind the very first included header file. I also notice that, under Windows, it cannot find my own header files unless I provide a relative path, e.g. #include "../Common.h" I can get make to find stdbool.h if I provide an absolute path to the compiler directory, but that exposes a web of additional broken links between files.
As a side note, the project builds successfully within Code Composer Studio, so I am assuming that this isn't an issue with my specific Windows environment nor with the code within the project itself.
This seems to be an issue with gcc.exe. I set an environment variable CC to the path of a different compiler (in my case a TI compiler) within my build script and that fixed the problem.

How to compile modsecurity on Ubuntu?

After I followed the instructions in (Building Custom ModSecurity Modules)section in modsecurity dev guide in order to compile (mod_tfn_reverse.c) using the command apxs -ca mod_tfn_reverse.c, I'm still finding "fatal errors" such as unable to find the file modsecurity.h mentioned in the header of the C document.
Here is the link to the source on github modsec
Instructions I did:
I am using Ubuntu 14.4 64bits (New installation with updates).
I installed "apache dev" package, to run "APXS" command on terminal.
Downloaded "modsecurity" zip file from github.
I extracted the zip file, then I located where the mod_tfn_reverse.c is.
It's path : ModSecurity/ext/mod_tfn_reverse.c
Then I changed the directory to the targeted file CD modsecurity/ext
as I placed the folder in "home".
Finally, I executed the command apxs -ca mod_tfn_reverse.c.
These are the instructions I did, apxs works, but the compilation fails because "modsecurity.h" declared in the header was not found, I searched this file I found it in another directory (ModSecurity/apache2/modsecurity.h).
So, the difficulty is, how can I successfully compile that specific file and have the module done and ready to use in apache2 server.
I am also confused about what are the other archives, headers, and development tools required to:
to compile a custom apache module.
to compile mod_tfn_reverse.c, in my case, knowing that this is only the starting point to create custom module for modsecurity.
This is covered by the included README:
apxs -I<MODSECURITY_SOURCE_CODE> -I/usr/include/libxml2 \
-ca mod_tfn_reverse.c

qmake -project: add new file extensions

I'm using QTCreator as a code editor for my C++ project, not using the real features of the qmake compilation process.
My project has several subdirectories, in all of which I ran qmake -project to create a duummy .pro file that simply lists the source and header files in the directory.
In my root folder, I simply created a "main.pro" file that includes all these "subdir/subdir.pro" files.
So it looks like this:
./
main.pro
subdir1/
/include
/src
subdir1.pro
subdir2/
/include
/src
subdir2.pro
Now my problem is, I use some files that have a special file extension (say, .ccp), which are actually some C code but are used in a different step of my compilation process.
They are naturally ignored by the qmake -project command and do not appear in my project.
I read here that I could use the qmake setting QMAKE_EXT_CPP to tell it to gather my files as a C-code file, but it doesn't seem to be working.
If I run qmake -query QMAKE_EXT_CPP, I get .cpp::.c::.ccp (which I set right before), but when running a new qmake, it doesn't take my .ccp files in account.
So, three questions:
Is it possible to make qmake take some special extensions as a C++ file, when building the .pro file?
If yes, is it correct to use the QMAKE_EXT_CPP setting?
If yes, what should be the syntax of the QMAKE_EXT_CPP setting? (mine inspired by this forum post, but it might be bogus).
You cannot change QMAKE_EXT_CPP with -project option. The list of cpp extensions used at this stage is hardcoded into qmake. However after initial creation of .pro file you can edit it to extend with support for other extensions:
in test.pro
QMAKE_EXT_CPP += .ccp
SOURCES += test.ccp
You have to add new files manually.

Resources