Vscode C++ Task.Json Include Path and Libraries (2023)

How do I set include path library directory and linker for VSCODE when I have Visual C++ build tools to work with (not g++)

As mentioned in the comments, you must use a C++ build system to manage dependencies and build your project. VSCode doesn't come with built-in build systems like Visual Studio.

VSCode tasks allow you to specify a command line, which can then be easily invoked in the IDE. The task shown is just a task of creating a running file, which is only really useful for trivial programs with no dependencies. It callscl.exeto the current source file (passing a few other arguments).

You can specify include directories and pass arguments to the linker by adding "args" to the array in the task, e.g. e.g.:

"/I", "D:\\Codebibliotheken\\boost_1_77_0",
"/link", "/LIBPATH:\"D:\\Codebibliotheken\\boost_1_77_0\\stage\\lib\"",

which assumes the Boost headers and (statically created) libraries are in the specified locations.

You could probably figure out how to build an entire project by adding command lines with VSCode tasks, but it's probably easier to use a build system (even if that system is CMake).

VSCode doesn't recognize includes from includepath

You haven't told your compiler about a file called Zipper.h or its location or anything related to it. "g++ test.cpp -o test" just tells the compiler to compile and link a source file called test.cpp. You must understand that Visual Studio Code is not an IDE and cannot be compiled by yourself. You should have a file called c_cpp_properties.json file in your .vscode directory. The one I'm using for example looks like this and is configured for mingw64.

{
"Configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/Source/**"
],
"compilerPath": "C:\\mingw-w64\\mingw64\\bin\\gcc.exe",
"intelliSenseMode": "gcc-x64",
"Browse": {
"Away": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": wahr,
"DatabaseFilename": ""
}
}
],
"Version": 4
}

This tells Visual Studio Code where your source files and libraries are located. This is used for intellisense (syntax highlights, error squiggles, code completion, etc.). However, this has absolutely nothing to do with the construction of your project. Now your compiler doesn't know about the include paths you set in Visual Studio Code. So in order to compile your project, you need to tell your compiler everything it needs to know. Visual Studio Code simply runs what you specify in the task. It's the same as going into that directory and typing the same thing into your command prompt. So I recommend you to read up on how to compile a C++ project with g++, your problem has nothing to do with Visual Studio Code at all. If you're planning on doing something a little larger than just a single source file, I highly recommend you learn CMake. Compiling by manually invoking gcc gets really complicated once you have more source files and includes/libraries to link. Once you have your cmake set up, you can simply specify a task in Visual Studio Code similar to this to build your project:

{
"Version": "2.0.0",
"Tasks": [
{
"label": "Build",
"type": "shell",
"Befehl": "cmake --build Build",
"Group": {
"Type": "Build",
"isDefault": true
}
}
]
}

I also recommend you to read this:
https://code.visualstudio.com/docs/cpp/config-mingw

This is a really good explanation of what exactly Microsoft is trying to do and helped me understand this when I first started using Visual Studio Code for my C++ work.

(Video) How to Fix Include Path Error in C/C++ Files using Visual Studio Code

Visual Studio Code, #include stdio.h labeled Add include path to settings

A more recent view of the situation. During 2018, the C++ extension added another option to the configurationCompilerPfadof thec_cpp_properties.jsonFile;

CompilerPfad(Optional)
The absolute path to the compiler you are using to build your project. The extension queries the compiler to determine the system include paths and default definitions to use for IntelliSense.

If used, theincludePathnot required as IntelliSense uses the compiler to figure out the system include paths.

Originally,

How and where can I add include paths in the following configurations?

The list is a string array, so adding an include path would look something like this:

"Configurations": [
{
"name": "Mac",
"includePath": ["/usr/local/include",
"/path/to/additional/contains",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include"
]
}
]

Source; cpptools blog March 31, 2016.

The linked source has a gif showing the format for the Win32 configuration, but the same goes for the others.

The example above includes the SDK path (OSX 10.11) when Xcode is installed.

(Video) Compiling Multiple Files in VS Code

noteI find that the update can take a while once the include path has been changed.

The cpptools extension can be found here.

More documentation (from Microsoft) on C++ language support in VSCode can be found here.

For the sake of retention (from discussion) below are basic snippets for the contents of the tasks.json file to compile and run either a C++ file or a C file. They allow spaces in the filename (requires escaping the extra quotes in the json with\"). The shell is used as a runner, enabling compilation (clink ...) and the execution (&& ./a.out) of the program. It also assumes that the tasks.json file "lives" in the local workspace (under the .vscode directory). Further details on task.json, such as supported variables etc. can be found here.

For C++;

{
"Version": "0.1.0",
"isShellCommand": true,
"taskName": "GenericBuild",
"showOutput": "always",
"Command": "sh",
"suppressTaskName": false,
"args": ["-c", "clang++ -std=c++14 -Wall -Wextra -pedantic -pthread \"${file}\" && ./a.out"]
}

for C;

{
"Version": "0.1.0",
"isShellCommand": true,
"taskName": "GenericBuild",
"showOutput": "always",
"Command": "sh",
"suppressTaskName": false,
"args": ["-c", "clang -std=c11 -Wall -Wextra -pedantic -pthread \"${file}\" && ./a.out"] // Befehlsargumente...
}

Visual Studio-Code: C++-Include-Pfad

Okay, that was silly, but in case anyone uses itVisual Studio-Codeand has no trivial project. These instructions assume you are using the Clang compiler:

  1. Open your project directory
  2. Open.vscode/settings.json
  3. Configure the following line inside the JSON object:

    // compiler options for C++ (e.g. ['-std=c++11'])
    "clang.cxxflags": [
    "-I/path/to/my/include/directory" // Header-Dateien
    ],

Elegant solution for VS Code C/C++, including path for IntelliSense and building project

Here's what I do: Uninstall Microsoft's C/C++ extension and replace it with Clangd for code completion and Native Debug for debugging. I've had better experiences with these two, including an easier configuration.

(Video) #include errors detected. update your include Path. How to fix this include path error in VS code !!

Clangd is configured by a single file calledcompile_commands.json, which is just a list of compiler flags for each source file.

Then start using an appropriate build system. For example, CMake can generate this file by default. For Make there is a tool to generate it. In a pinch, you can write it yourself.


Related topics

Here's how to peek at the next element in a range-for loop

Why should I use <Bits/Stdc++.H≫

What are R-values, L-values, X-values, Gl-values ​​and Pr-values?

How to get the list of files in a directory using C or C++

Output Unicode strings in the Windows console app

How to implement classic sorting algorithms in modern C++

(Video) Include c/cpp third party libraries in Vscode(windows) Msys2-Gcc

Why are C character literals ints instead of chars?

How to declare an interface in C++

Avx2 What is the most efficient way to pack links based on a mask

View a C/C++ source file after preprocessing in Visual Studio

Vector converted all negative values ​​to zero

What is object slicing?

Passing a 2D array to a C++ function

Can num++ for 'int num' be atomic?

"Unwrap" a tuple to invoke an appropriate function pointer

(Video) Build a C++ project in VS Code

What is a virtual base class in C++?

Is Delete[] equal to Delete

What is the lifetime of a static variable in a C++ function?

FAQs

HOW include C++ libraries in VS Code? ›

Install Visual Studio Code. Install the C/C++ extension for VS Code. You can install the C/C++ extension by searching for 'c++' in the Extensions view (Ctrl+Shift+X). Install the Microsoft Visual C++ (MSVC) compiler toolset.

How do I change the include path in Visual Studio code? ›

Visual Studio Code and the C/C++ language plugin need to be able to locate all of the header files referenced in our programme in order to understand it. The lightbulb to the left of the error will be seen if the pointer is on it. Then update the “includePath” setting by clicking that.

What is includePath in Visual Studio Code? ›

includePath An include path is a folder that contains header files (such as #include "myHeaderFile. h" ) that are included in a source file. Specify a list of paths for the IntelliSense engine to use while searching for included header files. Searching on these paths is not recursive.

How will you include a library in C++? ›

Right-click on the application project node in Solution Explorer and then choose Properties. In the VC++ Directories property page, add the path to the directory that contains the LIB file to Library Paths. Then, add the path to the library header file(s) to Include Directories.

Can you include C libraries in C++? ›

Yes - C++ can use C libraries. Except of course that you're using the C++ version of cstdio . To use the C one you need to #include <stdio. h> .

How do I get the full path of a file in VS Code? ›

How to show full file path in Visual Studio Code
  1. Select File > Preference > Settings. Visual Studio Code Settings.
  2. Click on WORKSPACE SETTINGS. Visual Studio Code Workspace Settings.
  3. Type window.title into the search bar. ...
  4. Click on the pencil tool and select Copy to Settings. ...
  5. Set the title to ${dirty}${activeEditorLong}

How to set G ++ to system path? ›

In the Windows search bar, type 'settings' to open your Windows Settings. Search for Edit environment variables for your account. Choose the Path variable in your User variables and then select Edit. Select New and add the Mingw-w64 destination folder path to the system path.

How do I change the full path in Visual Studio? ›

In Visual Studio, click Tools > Options. Expand Projects and Solutions and click Locations. The Projects location field defines the default location for storing new projects. You can change this path if you are using a different working folder.

How do I add the include path in Visual Studio? ›

Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio. Select the Configuration Properties > C/C++ > General property page. Modify the Additional Include Directories property.

How to setup cpp in VS Code? ›

For CPP Programming:
  1. Install Mingw-w64 via the SourceForge website. Click Mingw-w64 to download the Windows Mingw-w64 installer.
  2. Run the installer.
  3. For Architecture select x86_64 and then select Next.
  4. Add the path to your Mingw-w64 bin folder to the Windows PATH environment variable by using the following steps:
Mar 4, 2021

Where is C_cpp_properties JSON in VS Code? ›

(solved) VS Code: proper location for c_cpp_properties. json? The c_cpp_properties. json is a file specific to the Microsoft C/C++ extension and usually exists only in the workspace folder.

What is the blue squiggly line in VS code? ›

It means you've modified that line since you last made a commit in version control.

How do you get rid of the blue squiggly lines in Vscode? ›

  1. Press command+shift+p (open command pallete)
  2. Then type Disable Error Squiggles.
  3. And click on that Disable Error Squiggles.
Apr 17, 2017

How do I get out of restricted mode in Vscode? ›

To disable the Restricted mode status bar entry:
  1. Right click in the status bar.
  2. Uncheck the workspace trust entry.
Jun 10, 2021

Do you need to include libraries in a header file C++? ›

If your class declaration references types in the header, you will need to include it there. If it's only in the implementation, then you can include it in the cpp file.

What are the 3 main libraries of C++? ›

The Diagnostics Library. The General Utilities Library.

How do I add a library to Visual Studio Code? ›

Start Visual Studio Code. In the Open Folder dialog, create a ClassLibraryProjects folder and click Select Folder (Open on macOS). Open the Terminal in Visual Studio Code by selecting View > Terminal from the main menu. The Terminal opens with the command prompt in the ClassLibraryProjects folder.

Does C++ have a lot of libraries? ›

The only problem is, since C++ is not a new language, and it has a large community in stack, there are many libraries you can make use of, so choosing the right ones can be quite a challenge.

Does C++ have a JSON library? ›

There's no native support for JSON in C++ but there are a number of libraries that provide support for working with JSON. Perhaps the most widely used is JsonCpp, available from GitHub at https://github.com/open-source-parsers/jsoncpp.

How do I install all C++ libraries? ›

How To Install And Use C++ Libraries
  1. Acquiring the Library. In order to use the library in our application, we first need to acquire the library. ...
  2. Install the Library. The next step once we obtain the library is to install the library. ...
  3. Include the Library path for the Compiler. ...
  4. Link the Library path.
Apr 12, 2022

What is relative path vs absolute path? ›

A relative path describes the location of a file relative to the current (working) directory*. An absolute path describes the location from the root directory. When learning to access data files through programming, we regularly use relative file paths.

How do you set a path to System Variables? ›

Windows
  1. In Search, search for and then select: System (Control Panel)
  2. Click the Advanced system settings link.
  3. Click Environment Variables. ...
  4. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. ...
  5. Reopen Command prompt window, and run your java code.

How do I add to my system path? ›

Start the System Control Panel applet (Start - Settings - Control Panel - System). Select the Advanced tab. Click the Environment Variables button. Under System Variables, select Path, then click Edit.

How to install gcc and g ++? ›

Installing C/GCC Compiler for Windows
  1. Step 2: Download MinGW. ...
  2. Step 3: Locate the MinGW-get-setup.exe File and Start Installation. ...
  3. Step 4: Specify Installation Preferences. ...
  4. Step 5: Download and Set up MinGW Installation Manager. ...
  5. Step 6: Select Packages Required for the Compiler. ...
  6. MinGW32-gcc-g++ Package.
Feb 21, 2022

How do I turn off path limit? ›

Solution:
  1. Go to Windows Start and type REGEDIT.
  2. Choose the Registry Editor.
  3. In the Registry Editor, navigate to the following location: at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem.
  4. Select the entry named: LongPathsEnabled.
Mar 8, 2020

How do I get rid of Max path limitations? ›

To enable long file paths in Windows, open Registry Editor, create a new DWORD named "LongPathsEnabled" in "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem" and set the value to 1. Pro and Enterprise users can enable "Enable Win32 Long Paths" in the Local Group Policy Editor.

How do I fix my path problem? ›

How to fix “The system cannot find the specified path” error
  1. Solution 1: Check path for errors.
  2. Solution 2: Check directory or folder.
  3. Solution 3: Remove invalid environment variable.
  4. Solution 4: Repair system files with SFC and DISM.
  5. Solution 5: Clean up Windows update.
  6. Solution 6: Reset Windows update components.
Nov 17, 2022

How do I import libraries into Visual Studio? ›

Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio. Select the Configuration Properties > Linker > Advanced property page. Modify the Import Library property.

How do I link libraries in VS Code? ›

Visual studio code extension: Add External libraries to project as symlinks.
...
Extension Settings
  1. Open command panel ( Shift+CMD+P on OSX or Shift+Ctrl+P on Windows and Linux).
  2. Search for 'Extlibraries: Add external library' and press Intro.
  3. Input external directory or file path.
  4. Input name and press Intro.
May 18, 2017

How do I add a reference library in VS Code? ›

Add a reference
  1. In Solution Explorer, right-click the References or Dependencies node, and then choose either Add Project Reference, Add Shared Project Reference, or Add COM Reference from the context menu. ...
  2. Select a reference to add, and then select OK.
Sep 30, 2022

How to install cpp library? ›

Installation on Windows is as simple as unzipping the contents of the library in a folder. On Linux, we can invoke the package manager to install the library. We need to set the path of the library so that the compiler knows where to look for the library files.

How do I manually add a library to processing? ›

Find the 'Processing' folder

Drag and drop the contributed library into the folder 'libraries' -- you should be able to add as many libraries like this as you want.

What is the difference between import library and from library import *? ›

The difference between import and from import in Python is: import imports an entire code library. from import imports a specific member or members of the library.

How do I import library files? ›

You can use LIB with the /DEF option to create an import library and an export file. LINK uses the export file to build a program that contains exports (usually a dynamic-link library (DLL)), and it uses the import library to resolve references to those exports in other programs.

How do I link a static library in code blocks? ›

Go to Project->Build Options->(Select project name) . Then select the Linker settings and click on the Add button under Link Libraries , and select libmysql. lib . This should statically compile your program, AFAIK.

How do I link libraries with GCC? ›

Procedure
  1. Change to the directory containing your code.
  2. Compile the program source files with headers of the foo library: Copy. Copied! $ gcc ... - Iheader_path -c ... ...
  3. Link the program with the foo library: Copy. Copied! $ gcc ... - Llibrary_path -lfoo ... ...
  4. To execute the program, run: Copy. Copied! $ ./program.

How to use vcpkg in VS Code? ›

I followed these steps:
  1. git clone vcpkg into home directory.
  2. add VCPKG_ROOT env variable that points to the directory.
  3. vcpkg install catch2.
  4. vcpkg integrate install.
  5. open vs code, I have already installed required cmake plugins.
  6. configure cmake project.
Mar 11, 2022

Videos

1. How to Set up Visual Studio Code for C and C++ Programming
(LearningLad)
2. Include Path Error in VS Code | 100% Fixed
(JayantSJ)
3. Setting up VSCode and Clang for C++ on macOS
(Mr. Jim)
4. include errors detected. please update your includepath SOLVED visual studio code C and C++
(United Top Tech)
5. Debug a C++ project in VS Code
(Visual Studio Code)
6. Debug Multi-File C++ Programs in VS Code and WSL (Windows)
(Michael Hoefer)
Top Articles
Latest Posts
Article information

Author: Jerrold Considine

Last Updated: 02/16/2023

Views: 5975

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Jerrold Considine

Birthday: 1993-11-03

Address: Suite 447 3463 Marybelle Circles, New Marlin, AL 20765

Phone: +5816749283868

Job: Sales Executive

Hobby: Air sports, Sand art, Electronics, LARPing, Baseball, Book restoration, Puzzles

Introduction: My name is Jerrold Considine, I am a combative, cheerful, encouraging, happy, enthusiastic, funny, kind person who loves writing and wants to share my knowledge and understanding with you.