Problems and solutions of cmake in vscode (recommended)

Time:2020-11-4

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!

Recommended Today

Regular expression sharing for checking primes

This regular expression is shown as follows: Regular expressions for checking prime numbers or not To use this positive regular expression, you need to convert the natural number into multiple 1 strings. For example, 2 should be written as “11”, 3 should be written as “111”, 17 should be written as “11111111111”. This kind of […]