The "C/C++ Compile Run" extension you are using only allows you to compile and run one file only, as indicated in own repository:
Compile & Run single c/c++ files easly on vscode
And so with this extension you will not be able to. However you can use the extension Code Runner which will already allow you to compile with multiple files, as well as compile into languages other than C or C++.
After having installed, access the extension settings by clicking on the sprocket of the same and accessing Settings.
On the screen of Settings access the Map Executor edit option, as shown in the following figure:
Add the following block before the }
closing file:
,
"code-runner.executorMap": {
"c": "cd $dir && gcc *.c -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
}
The archive should look similar to the following:
Note that there should be a comma separating the new option from the last one already in the file.
Now just go to the arrow to compile and run:
The option placed in the file compiles all . c that are in the folder you are running in, so you can later change that build statement to another one if you need to. How the execution is by the folder where it is, you must ensure that you have opened in Vscode with "Open Folder" the folder that has your files . c to be compiled.
It is also useful to mention that the added instruction is valid for compiling with gcc, and so you have to adjust it if you are compiling with other compilers like Clang.
Additionally the instruction also assumes that gcc is available in PATH, either windows or linux.
The multi-file build instruction with gcc, the *.c
, is not supported in older versions of gcc
, and so it is recommended that you have a minimally current version of gcc (something like version 7 or higher).
This answers your question? How to Compile in C using custom hearders in Vscode?
– Denis Rudnei de Souza
Unfortunately no, I don’t know how to configure this part.
– Pierre Campos
Your
main
is being compiled separately. How to compile ?– Isac
@Isac I am compiling using an extension called C/C++, but it seems that the head. c and head. h files are not being " linked " you know ? In Dev-C++ if I do it like I did in Vscode, it can already do the link " "
– Pierre Campos
@Pierrecampos But are you using the Code Runner extension to compile and run ? or are you doing it yourself by the terminal ?
– Isac
@Isac, I’m compiling with C/C++ Compile Run
– Pierre Campos
Honestly I do not think it is possible to solve with this extension. If you look at the repository of this extension on github see the following: "Compile & Run single c/c++ files"
– Isac
Yeah, that was my fear, good but thank you for your attention
– Pierre Campos