S3 (and next ...) : setting include path to VSCode so it can find your header files
Description of the problem
Maybe some of you still have this problem : starting from S3, when a Makefile
should be used to compile your code, compilation works using the make
command, but there is still some error shown in VSCode, because it cannot find your code. Here are a few tips to solve this ...
Solution
c_cpp_properties.json
file
Use of a In your project, you have a .vscode directory where VSCode put all the settings associated to this project. Just add in there a file named c_cpp_properties.json
, and write the following configuration in it :
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/[studentID]/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
Here I consider that your project repository, represented by the workspaceFolder
variable, is simply the gitlab repository of your group (that contains each student repository named with their studentID). So replacing [studentID]
with your own studentID will indicate to VSCode to search header in all of your sub-directory in your own.
Handling same header files for different series
One issue can occurs if you use the same name header files for different exercises. Since VSCode will look into each exercise series, it may mix the different includes together. To avoid this, just specialize the includePath link :
"includePath": [
"${workspaceFolder}/[studentID]/s3/include"
],
for S3. You also add multiple directory to the includePath using for instance :
"includePath": [
"${workspaceFolder}/[studentID]/s3/include",
"${workspaceFolder}/[studentID]/s4/include",
],
just don't forget the comma