To install the vscme plug-in, follow the steps of installing vscode on the Internet
After installation, create a new folder / project as follows:
Among them, build is automatically generated after opening the folder. In test, there are source files, project files, etc.
Open the terminal (it can be either the terminal in the PowerShell or vscode), enter the build, and use the
cmake -G "MinGW Makefiles" ..
MinGW makefiles can be modified to other compilation options. Choose according to the wrong prompt.
If the configuration of cmake is wrong, it is possible that the kit is not selected, and the input is Ctrl + Shift + P
Cmake: Select a Kit
Select a kit. Here I choose the GCC option with MinGW. If not, choose another one.
After success, makefile will be generated. The Internet says to input
make
To generate executable files, but I always report errors here:
Make: the 'make' entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Check the spelling of the name, and if you include a path, make sure the path is correct
, and then try again.
Position line: 1 character: 1
+ make -v
+ ~~~~
+ CategoryInfo : ObjectNotFound: (make:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
(to solve this problem, we also download GNU make and add the corresponding system environment variables. But it didn’t solve the problem. Finally, GNU make is unloaded.) The make command is actually to call the make EXE file. You don’t need to enter the path because the corresponding path is added to the environment variable. But in fact, the make command has been installed when installing MinGW. The reason why it can’t be called is that the EXE file has not been changed to make.exe 。 have access to
mingw32-make
To execute the make command, you can also set mingw32- make.exe Renamed as make.exe , and enter
make
To execute. After success, the input is continued at the terminal
./TEST_C.exe
Among them, test_ C is the project name. So you can get the output of the program.
Attachment:
CmakeLists.txt Content:
cmake_minimum_required (VERSION 3.0)
project(Main)
set(CMAKE_C_COMPILER "gcc")
add_executable(TEST_C test/test_mod.c)
test/test_ The contents of mod. C are as follows:
#include<stdlib.h>
#include<stdio.h>
int main(){
int a = -123;
int b, c;
b = a / 10;
c = a % 10;
printf("%d, %d\n", b ,c);
system("pause");
}
summary
This article about vscode in the use of cmake encountered problems and solutions to this, more related vscode using cmake content, please search the previous articles of developeppaer or continue to browse the related articles below, I hope you can support developeppaer more in the future!