当前位置:网站首页>Configuring the command line compiled environment -msvc

Configuring the command line compiled environment -msvc

2022-06-11 03:07:00 shlyyy


although vs2019 It's very easy to use IDE, But sometimes command-line compilation is easier to use , The following is how to use the configuration MSVC Compiler environment .

One 、 install vs2019

vs There are a lot of them on the Internet , If not, Baidu will do it

Two 、 Configure environment variables

installed vs2019 You'll find out later vs2019 There will be one under the same drive letter of Windows Kit Folder .
Open the environment :
 Open Settings
Click on the first system
 Click System
Find the bottom one about , There is an advanced system setting under the relevant setting column
 Find the bottom one about
 Insert picture description here
newly build WIN10_INCLUDE environment variable

E:\Windows Kits\10\Include\10.0.19041.0

newly build WIN10_LIB environment variable

E:\Windows Kits\10\Lib\10.0.19041.0

newly build MSVC environment variable :

E:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133

newly build INCLUDE environment variable , Add the following 4 item :

%WIN10_INCLUDE%\ucrt

%WIN10_INCLUDE%\shared

%WIN10_INCLUDE%\um

%MSVC%\include

newly build LIB environment variable , Add the following two items :

%MSVC%\lib\x86

%WIN10_LIB%\ucrt\x86;%WIN10_LIB%\um\x86

What I choose here is to compile 32 Bit program , So it is x86 Folder , If it is 64 Bit program can be changed to x64, The same goes for the following .

stay Path Add the following path to the environment variable

%MSVC%\bin\Hostx86\x86

3、 ... and 、 Test environment

newly build test.c file

#include <stdio.h>

int main()
{
	printf("Hello world!\r\n");
	return 0;
}

Open the command line , Switch path to test.c Under the folder :
After executing the following compilation instructions, a test.obj file

cl /c /W3 test.c

Executing the following link instruction will generate a test.exe Executable file

link test.obj

Finally, enter directly test Can execute test.exe
 Command line test

For convenience, direct , Perform the following run.bat Script , Ready to compile , link , perform :

del *.obj
del *.exe
cl /c test.c /W3
link test.obj
test.exe
pause

Four 、 Reference resources

Visual Studio 2019 To configure MSVC environment variable , Compile using the command line

stay VS code Use in MSVC+ Command line compilation generates C++ Program

原网站

版权声明
本文为[shlyyy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110242500525.html