My problems console in Visual Studio Code is showing me the following up message:
#include errors detected. Please update your includePath. InteliSense features for this translation unit
cannot open source file "omp.h"
This message is being showed even after I linked the path of omp.h after found it with:
find /usr -name omp.h
My c_cpp_properties.json file:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/omp.h",
"/usr/include/c++/7.2.0",
"/usr/include/c++/7.2.0/x86_64-pc-linux-gnu",
"/usr/local/include",
"/usr/lib/clang/5.0.0/include",
"/usr/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/omp.h",
"/usr/include/c++/7.2.0",
"/usr/include/c++/7.2.0/x86_64-pc-linux-gnu",
"/usr/local/include",
"/usr/lib/clang/5.0.0/include",
"/usr/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
]
}
What am I missing out? And how to fix it?
I've fixed changing the path to:
"/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/"
Removing the omp.h file.
Related
I tried to compile codes and i have an error.
In file included from ui.c:1:
./ui.h:3:10: fatal error: 'SDL.h' file not found
#include <SDL.h>
^~~~~~~
1 error generated.
but i've already installed SDL library on my mac and set includePath on VScode.
here is a setting of my cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/Users/kimdongju/Dungeonrush/src/**",
"/usr/local/Cellar/sdl/1.2.15_3/include/SDL/**",
"/usr/local/Cellar/sdl2/2.0.20/include/SDL2/**",
"/usr/local/Cellar/sdl2_image/2.0.5/include/SDL2/**",
"/usr/local/Cellar/sdl2_mixer/2.0.4_3/include/SDL2/**",
"/usr/local/Cellar/sdl2_net/2.0.1/include/SDL2/**",
"/usr/local/Cellar/sdl2_ttf/2.0.18_1/include/SDL2/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs
/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++98",
"intelliSenseMode": "macos-clang-x64"
}
],
"version": 4
}
The source code is very simple.
#include <signal.h>
void main() {
sigset_t set;
}
The signal.h has been included in which sigset_t should have been defined. But vscode still report a problem.
identifier "sigset_t" is undefined
The config file is as below.
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++98",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}
And the program can be successfully compiled with no error. Why does vscode report that error?
The problem here is that sigset_t is only defined if _POSIX_C_SOURCE is defined.
With the C standard that gcc uses by default, _POSIX_C_SOURCE is already defined. So compiling your program with gcc doesn't produce an error.
To solve this you can add "cStandard": "gnu11" to you config file, or add "defines": ["_POSIX_C_SOURCE=199309L"].
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++98",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}
I am using VSCode in Linux for my project. I have this curly line under the include lines of my header files
I included correctly the include path as defined in the file c_cpp_proprieties.json as follow:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64",
}
],
"version": 4
}
Please any solution to resolve this problem.
When you compile it on gcc you have to include the include library.
The include path in settings didn't work out for me.
Changing it on the build task for gcc did fix it.
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"-I",
"${workspaceFolder}/ds/include/",
"${workspaceFolder}/ds/src/${fileBasenameNoExtension}.c",
"-o",
"${workspaceFolder}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/gcc"
}
]
Adding the desired path in the c_cpp_properties.json as well as the folder to the Visual Studio Code workspace (File -> Add folder to workspace) appeared to solve the issue for me.
Let's say this is my project.
file structure:
project_root
|-- inc
| |-- header.h
|-- src
| |-- helpers.c
| |-- main.c
header.h
#ifndef HEADER_H
# define HEADER_H
void func(void);
#endif
helpers.c
void func()
{
/* do something */
}
main.c
#include "header.h"
int main(void)
{
func();
return (0);
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/inc",
],
"defines": [],
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
tasks.json
"tasks": [
{
"type": "shell",
"label": "gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"-Wall",
"-Werror",
"-Wextra",
"-o0"
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build",
"isDefault": true
},
}
],
"version": "2.0.0"
}
Issue
When I build my program in VSCode, I get the following error.
project_root/src/main.c:xx:xx: fatal error: 'header.h' file not found
Question
How do I avoid this error?
(How do I let the VSCode's build feature know where my header is?)
What I did already
I configured my include path(s) in c_cpp_properties.json, so I'm not getting the squiggles in main.c, where I include my header.
What's not going to be a solution for me
I don't want to write #include "../inc/header.h" in main.c, so this would not be a solution for me.
specify the include paths in tasks.json, under the args property, using the -I flag.
{
"tasks": [
{
"type": "shell",
"label": "gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"-Wall",
"-Werror",
"-Wextra",
"-o0",
"-I${workspaceFolder}/inc",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build",
"isDefault": true
},
}
],
"version": "2.0.0"
}
I keep receiving undefined identifier errors when invoking stdin and stdout despite having included stdio.h. I have looked for solutions to this but haven't found anything yet. Weirdly the program is still able to compile. I have already instructed the c_cpp_properties.json file to include the location of the header files in its path. If anybody would be able to help resolve this issue it would be greatly appreciated. Thank you.
VSCode version: Version 1.18.0 (1.18.0)
OS: macOS 10.13.1
Errors shown in the "Problems" section of VS Code
c_cpp_properties.json file
{
"configurations": [{
"name": "Mac",
"includePath": [
"/usr/include",
"/Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include/",
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1/tr1/",
"/usr/include/c++/4.2.1",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/include/c++/4.2.1",
"/Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include/",
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1/tr1/",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
]
},
{
"name": "Linux",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "Win32",
"includePath": [
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include",
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 3
}