Accustomed to Linux under the GCC compiler tools, like the command line to compile the link C program, incredibly also found that I installed the VS tool did not see directly compile the C program tools (I am not familiar with this). The compile file command for VS is cl, and the link command is link. Referring to the data on the Internet, the compiler file with the extract vs is used as a tool to compile the program in a command-line way. The following steps are:
1, create folders in your own directory, such as: D:/vctool;
2, the VS installation directory under the VC directory of Bin, lib, include directory to the Vctool directory;
3, copy the Lib directory under the C:/Program Files/microsoft sdks/windows/v6.0a (or similar directory, vs installation file) to the Vctool directory, and remember not to overwrite it but rename it sdklib;
4, now the required command files and class libraries, include files are copied over, add the bin directory to the environment variable path;
5, you can then write the C language file test.c:
#include "stdio.h"
__declspec (dllexport) int sum (int a, int b)
{return
a + b;
}
5, write the compilation file: BUILD.bat:
Set path=./;D:/vctool/bin;%path%
set include=d:/vctool/include
set Lib=d:/vctool/lib;d:/vctool/sdklib
cl/c test.c
link/dll test.obj
Pause
6, double-click Run BUILD.bat, found compile error, cannot find Mspdb80.dll file:
So in the VS installation directory search, copy the file to the Vstool/bin directory, and then double-click BUILD.bat Compile, compile successfully, the directory has been generated:
Test.dll Test.lib Test.obj
If the link appears link:fatal error LNK1104: Unable to open the file "Kernel32.lib" error, it is because Sdklib did not copy the right or not set to the environment variable lib (build.bat)
The following are the relevant information found on the Internet:
2. The following CL command is described in detail below:
Cl.exe is a 32-bit tool that controls the Microsoft C and C + + compilers and linker. compiler produces common object file format (COFF)
Object (. obj) file. The linker produces an executable file (. exe) or a dynamic-link library file (DLL).
Note that all compiler options are case-sensitive.