I am learning C++ and I want to use VS Code as my code editor. I created a simple project that has a file with the main method and 2 other files to define a class (a .h
and a .cpp
). I created the default build task in VS Code to compile my code (g++ build active file
), only to get a compile error: undefined reference
for the class constructor. I saw that it was related to the linker not finding the implementation because it wasn't included in the build. So I modified my build task to build all .cpp
:
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${fileDirname}/*.cpp",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
But now when I build the project, I get this error: /path/to/project/*.cpp": No such file or directory
. Meaning that *.cpp
wasn't interpreted as a wildcard. I am using the default C++ extension for VS Code if is relevant. Am I missing some configuration in my task? How can I make this work? For a large project the method in which I manually add all cpp
files as arguments is obviously not appropriate so I would like to make this method to work. Thanks in advace!