I am trying to start developing with C++ in microsoft's visual studio code.
I have visual studio build tools installed with the "desktop development with C++"
I have the C++ extension in vs code installed.
I get an error whenever I try to run a .cpp file
Pls help
I take the following steps:
- I run the developer command prompt for visual studio
- I navigate to "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\projects\helloworld"
- I type "code ."
- visual studio code opens and I create a "main.cpp" file
- I enter the code:
int main(){
return 0;
}
- I click "run C/C++ file" and select "C/C++: cl.exe build and debug active file"
- It attempts to run but pops up the error message "The preLaunchTask 'C/C++: cl.exe build and debug active file' terminated with exit code -1
- The full error message is as follows:
Starting build...
cl.exe /Zi /EHsc /nologo "/FeC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\projects\helloworld\main.exe" "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\projects\helloworld\main.cpp"
main.cpp
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
Build finished with error(s).
* The terminal process terminated with exit code: -1.
* Terminal will be reused by tasks, press any key to close it.
Another option is to compile it with Visual Studio Code. They have a great tutorial you can follow here. However, the part you would want to start is how to install MinGW-x64. Once that is done, the best way I have found to compile the programs is through the terminal window you can open in VSCode. Then run this
g++ insert_code_name.cpp -o insert_code_name. Then, to run that code do./insert_code_name. If you need any further help, just let me know!