Windows Programming, program compilation uses the command-line tools.

Source: Internet
Author: User
Tags visual studio 2010

Windows Programming, program compilation uses the command-line tools.

The 1.cl.exe file is a compiler for visual c\c++ that compiles program source code files into an obj file.


The 2.rc.exe file is a resource compiler. In the project. The RC file contains a description of the resources used in the program (menus, icons, and so on). Rc.exe will. The RC format file is compiled as a. res file, and the linker is linked to the executable file.


3.link.exe is a linker for the Windows platform that will cl.exe compile generated obj files, the. res files generated by the resource compiler, and the Lib files in the Lib directory into executable exe files, DLL files, and so on.

After the program has been compiled, the resulting file is an object file with an obj extension, and link.exe is a tool that links object files and libraries to create executable program files or dynamic-link library files.

Link.exe input files include obj files, lib files, exp files, def files, res files, txt files, ilk files. Output files are exe files, DLL files, sys files, and other executable program files.

Other tools

1. BSCMAKE. Exe
Generate an information file (. BSC), which is used to browse the information for symbols (classes, functions, data, macros, and types) in a program. You can view this information in the Browse window of the integrated development environment (the. bsc file can also be generated in the IDE).


2. LIB. Exe
LIB library files for generating the COFF format, which can be used to create export files and import libraries referencing export definitions, are useful when providing development interfaces for other developers.


3. EDITBIN. Exe
Can be used to edit binary files in the COFF format.


4. DUMPBIN. Exe
You can display information about COFF binaries, such as symbol tables.
For example, use Dumpbin.exe to analyze the Start.exe of chapter 1th. Select tools → Visual studio command Prompt to switch to the directory where the Start.exe is located and run:
The bin_info.txt contains very rich information in the executable file, including header information, section information, and so on.


5. Nmake. Exe
Program Maintenance Utility to read and execute generated files. will be detailed in section 3.3
Describes the use of NMAKE.


6. ERRLOOK. Exe
The Error Lookup tool, used in conjunction with the GetLastError API function, plays a lot of role in debugging the Windows API's call errors. As shown in 3-1, in the visual Studio IDE, you can use the menu "Tools" → "Error Lookup".

Using the cl.exe compiler from the command line

Http://www.cnblogs.com/LCCRNblog/p/4532643.html

Command-line mode compiles faster than compiling in the IDE, and avoids interference with some additional information generated by the IDE, as described below in compiling C + + under the Win7 command line.

1. First to install Visual Studio 2010 correctly, install the path (D:\Program Files)

2. Set Environment variables:

Path=d:\program Files\Microsoft Visual Studio 10.0\vc\bin

Include=d:\program Files\Microsoft Visual Studio 10.0\vc\include

Lib=d:\program Files\Microsoft Visual Studio 10.0\vc\lib

2. Write a Hello World C + + program

/*the First C + + program*/#include <iostream>using namespace Std;//main functionint main () {    cout<< ' Hello world! " <<endl;    cout<< "This is my first C + + program.\n";}

Save Path C:\Users\zhongqin.mi\hello.cc

3. Restart the computer, open the command line, execute the following command

where CL is the command that invokes the compiler,-GX is an option that is necessary when compiling the program using the command-line interface. The Microsoft compiler automatically generates an executable file with the same name as the source file.

This executable file has an. exe suffix and has the same name as the source file, and more information can be found in the compiler User Guide.

Note: (Added May 27, 2015 15:45:59)

In the second step of the configuration of the environment variable, in fact, can not be configured, just before each use of cl.exe, run the Vcvarsall.bat (under the "VS Installation path \VC" path), run Vcvarsall.bat, you can use Cl.exe, Link.exe and Nmake.exe, just run the vcvarsall.bat before each use, and only run Vcvarsall.bat cmd window to use the above three exe.

4. Frequently Asked Questions

4.1 If you are prompted not to find the Mspdb100.dll file, from D:\Program Files\Microsoft Visual Studio
10.0\Common7\IDE copy "Mspdb80.dll" four files to D:\Program
Files\Microsoft Visual Studio 10.0\vc\bin.

4.2 If you encounter a prompt when you execute the CL command link:fatal error LNK1104: Unable to open the file "Kernel32.lib", C:\Program Files\Microsoft Sdks\windows\v7.0a\lib Recorded kernel32.lib copy to D:\Program.
Files\Microsoft The Visual Studio 10.0\vc\lib directory.

--------------------------------------------------------------------------Split Line-------------------------------------------- ----------------------------

May 27, 2015 16:51:38

If you have more than one file to compile a connection with, do it yourself with the following simple introductory experience.

First create the following source file Heade.h,header.cpp,main.cpp

Header.h

#ifndef _header_h#define _header_hclass a{public:    A ();    A (int);    void print ();p rivate:    int member;}; #endif

Header.cpp

#include "header.h" #include <iostream>using namespace std; A::a () {    member = 0;} a::a (int init) {    member = init;} void A::p rint () {    cout << member <<endl;}

Main.cpp

#include <iostream> #include "header.h" using namespace Std;int Main () {    cout << "Hello world!\n";    A (a);    A.print ();    return 0;}

Then follow the method described above, enter in cmd: CL main.cpp header.cpp

Using the NMAKE tool to compile the connection C + + source code in a Windows environment

Recently, when writing code, you need to execute the generated C + + source code file by command, so you need to learn about how to use commands to compile and connect C + + original files in a Windows environment. This article is a self-groping practice to draw. As a starting point for yourself, follow up with a deep understanding of this knowledge.

1. Preparation

Write the main.cpp header.h header.cpp three source code files and put them in a folder test.

2. Writing NMAKE files

Create the Hello.mk file in the test folder and write the following script

Foo:main.obj header.obj    cl.exe-ehsc main.obj header.obj-o foomain.obj:main.cpp    cl.exe-ehsc-c main.cppheader . obj:header.h header.cpp    cl.exe-ehsc-c header.cpp clean:    del *.obj *.exe

Note that the script hollow lattice needs to be preserved, cannot be arbitrarily added and deleted. As for why, I am not very clear, follow-up slowly understand learning.

-----------------------------------------------------------------------------Supplement May 29, 2015 17:17:56------------- -----------------------------------

The second line CL.EXE-EHSC main.obj header.obj-o foo, this row-o parameter is passed a cl.exe, the parameters after-O (including-O) is passed Link.exe.

--------------------------------------------------------------------------------------------------------------- -------------------------------------------

In the course of practice, I put "header.obj:header.h header.cpp" This line of Header.h removed, re-execute the script file, still able to pass, this reason I am not quite clear, because I have just touched on this knowledge, but also need to further try to further understand the principles.

Then open cmd, navigate to the test file path, first execute Vcvarsall.bat (the method is covered in the previous article), and then execute the following command

nmake/f hello.mk

The Foo.EXE executable file is generated in the Test folder.

If you execute the following command

nmake/f hello.mk Clean

All *.obj and *.exe generated in the test folder will be deleted.

C run-time Error R6034 Problem Resolution

1, problem description

For the last two days, I've been writing a small project with vs2008 that needs to be in C + + The code calls Cl.exe and link.exe through the command line, which is to pass the parameters to the compiler CL and linker link, and then compile the link to the executable exe. The resulting Result.exe runtime is running out of time. Error R6034 an Application has made a attempt to load the C runtime Library incorrectly. The error, around this problem, I checked the information for two days, finally finally solved.

Here is a simple record of the solution, easy to use later.

2. Problem solving

Before compiling the chain using the command line to deliver the executable file, you can bring out the source program (. cpp,.h) file that needs to be passed to cl.exe, use these source files to create a vs2008 project manually, and then compile the link for the VS2008 project to generate the executable file. This step is to ensure that the generated executable is the result you need, if this manual project can not generate the exe you need, the command line generated by the EXE is certainly not the result you want to get.

After building a good vs2008 project and doing the right thing in this project---> Properties-->c/c++---> Command line, you will see a lot of commands, in fact this is the command passed to Cl.exe, the same truth, in the project---> Properties-- > Linker---> Command line can see the command passed to Link.exe.

According to the method described above, I wrote the code in my project to generate an EXE automatically. Then click on this exe to appear runtime error R6034.

Here is the original text that addresses the problem:

An application have made an attempt to load the C runtime library without using a manifest. This is an unsupported-a-to-load Visual C + + DLLs. You need to modify your application to build with a manifest. For more information, see the "Visual C + + Libraries as Shared side-by-side assemblies" topic in the product documentation.
Applications must use a manifest to load the C runtime library. For more information, see Visual C + + Libraries as Shared side-by-side assemblies and Manifest Generation in Visual Studio.
In release builds, the diagnostic message reads: ' An application have made an attempt to load the C runtime library Incorre ctly. Please contact the application's support team for more information. "
To correct this error
Rebuild your application to include a manifest. Building an application with Visual Studio automatically puts the manifest into the resulting. exe or. dll file. If you were building at the command line, use the Mt.exe tool to add the manifest as a resource. Use the Resource ID 1 if you build a. exe, and resource ID 2 if you build a. dll. For more information, see how to:embed a Manifest Inside a C + + application.

The main point is this: If you're building at the command line, use the Mt.exe tool to add the manifest as a resource. Use the Resource ID 1 if you build a. exe, and resource ID 2 if you build a. dll. For more information, see how to:embed a Manifest Inside a C + + application.

In this case, the command line not only needs to call Cl.exe and Link.exe, but also calls a mt.exe, mt.exe parameter is actually created above the VS2008 project under Project---> Properties---> Inventory Tool----> The command line has the relevant command arguments. After you add this command to the command and re-execute it, the problem is resolved.

WIN32DLL,MFC regular DLLs and MFC extension DLLs

Win32dll uses the Win32 API implementation, can only export functions, can be called by various applications, the widest range of application.

MFC regular DLLs are created for MFC, just as MFC programs are related to WIN32 programs, as are the relationships between MFC regular DLLs and Win32dll. It uses MFC's mechanism to export only standard C functions. Thus, it can be called by most Win32 programs.

MFC extension DLLs are also used by the MFC mechanism to create, compared to the MFC regular DLLs, extension DLLs can export C + + classes and MFC derived classes, so that the scope of the DLL's interface expanded. This long, MFC extension DLL Application scope is small, can only be called by the MFC program. Because it exports more than just functions, there are also C + + classes and MFC derived classes.

In addition, all dynamic-link libraries have two ways of linking: implicit invocation and display invocation. Implicit linking is easier to use, but not flexible enough; the display link can be loaded when the DLL is actually used, and released at the appropriate time, with a relatively complex operation.

Most common Windows data types

Common environment variables

Windows Programming, program compilation uses the command-line tools.

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.