Extract vs file Compiler of class GCC and compile C program for DLL dynamic link library

Source: Internet
Author: User
Tags command line microsoft c

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.