"Learning record" on the Internet learning Skills exercises and learning notes and learning experiences of makefile (VS2010)

Source: Internet
Author: User
Tags echo b

I don't know. As a complete Windows platform under the less professional software engineering students, see the "Accelerated C + +" source code, the first reaction is: Oh! I should use make to generate project files. Then I happily use AOL to start searching for relevant information.

And then the egg! I must have been possessed by some strange creature. I should import files directly with VS Create Project. Then ... ctrl+f5. How perfect.

But...... Following:

"Tutorial" from the cloud-wind Big blog (cloud-Wind blog)

IDE is not the only choice for programmers (i)

and the following (ii) (iii) (IV)

And a big one-half, just to illustrate the steps to compile and link a program with CL to make a lead-out tool. I ... "manual face without expression

in fact, I guess it should be a big whim to write an article on how to use the CL command to compile the program, to those who are curious, not in accordance with the common sense of the card, but the eggs and no very good learning ability novice some guidance. And then...... is out of hand. That's why there's such a weird space structure? All right, I admit it's just my brain tonic, and I've been feeling more and more lonely as a programmer, and the machine won't talk to me. Every time it talks to me it's time for my code to have a problem ><, and I really have to light up in a boring environment can rely on humming songs and self-brain complement the perfect mood adjustment skills . Of course, these are all nonsense.

Related errors and remediation methods are described in subsequent articles. Below, let's jump. Oh, into the strange play, here is my study record.

"Part.1" vs2010 with CL for compile link work and path setup and problem resolution

Step Record:

Command line (win+r, input cmd space call) mode, enter

CL FOO.C

The system will generate Foo.obj,foo.exe two files, the compiler principle of the teacher said, program generation is compiled first, then link the process. If the compilation is generated in the middle code form, it seems to be a compilation? Then the chain is delivered into a binary program, which is the abbreviation for exe,executive, if I'm not misspelled. Well. Remembering or spelling mistakes is not a qaq of face.

Cloud wind greatly said, CL This command is to compile, link this process to add a shell, or we should be fashionable to say, encapsulate it?

Well, if you are prompted for any errors, please check if your foo.c is present.

The following is an error record

    1. INPUT CL hint missing Mspdb.dll error.
    2. Prompt iostream after entering command: Missing file support
    3. Prompt cannot open file "kernel32.dll" after entering command

Related workarounds are linked to the issue.

Of course, you may be because of the egg my roommate is playing games/with thunder My network is Tofu slag and do not want to jump, of course, you may jump after the discovery too long do not look. OK, here's the ... My solution.

    1. The big solution to the cloud is to run the VS installation directory/common7\tools\vsvars32.bat (or vsvarsll.bat) script, which sets the environment variables required for the VS run. I used the environment variable path to add: vs installation directory \Common7\IDE. (Environment variables are open with environment variables, properties, advanced system settings, my Computer (right))
    2. Environment variables total new LIB and include variables, (LIB) C:/Program Files/microsoft sdks/windows/v6.0a/lib; C:/Program Files/microsoft Sdks/windows/v5.0/lib; vs Install directory/vc/lib (INCLUDE) vs install directory/vc/include (OK Vsvarsall.bat solve all the problems!!! )
    3. Copy the Kernel32.lib from the C:\Program Files\Microsoft Sdks\windows\v7.0a\lib directory to the VS installation directory \vc\lib directory.
CL FOO.C bar.c//Multiple file chaining, default generated EXE name is called First source file name

  

There are no spaces between Cl/fefoobar foo.c bar.c//Generate Foobar.exe,/fe and Foobar.

Cl/fefoobar foo.obj bar.objlink/out:foobar.exe foo.obj bar.obj//both equivalent

Debugging:

Cl/zi foo.c

Next, the cloud will impart a unique cheat-book on debugging.

Do you know how the debugger implements the breakpoint function? In fact, it secretly in your program to set the breakpoint location placed a debug interrupt instruction. On a x86 32-bit system, this is a single-byte instruction, and the assembly code is int 3. When the CPU runs the program, when it encounters int 3, it will give control to the debugger, and when you choose to continue running in the debugger, the debugger will replace the replaced program machine instructions back, so that the program can continue to run.

Knowing this detail, we can set the debug breakpoint on our own in advance. I call it a hard breakpoint. As long as the program is running, it will definitely stop. If you want to mask hard breakpoints at run time, you need to do some work on the source code.

Now add a line __asm int 3 at the entrance of your FOO.C program (if you are using GCC to add ASM ("int $ $"), and re-compile it with cl/zi foo.c once. Then run Foo.EXE directly on the command line.

Immediately, you will see a familiar dialog box about the crash of the program. It doesn't matter, it is caused by the hard breakpoint (int 3) you inserted. If you install vs correctly, VS should have set itself as the default debugger for the system. Click on the button on the dialog to launch the VS IDE, and we will find that the program is parked exactly where the int 3 line is assembled. Now you can follow through with a single step.

Http://blog.codingnow.com/2008/09/replacement_of_ide_1.html

In fact, error->vs debugging, however, vs debugging is not skilled ....

"Part2" make tool

MinGW's gmake is highly recommended for cloud winds. Keyword MinGW GNU make

The way of programming is to make machines do things, people focus on people's thinking. If you really typed each of the instructions by hand, it would certainly have made the programmer do the machine thing. Writing a compilation instruction to a batch (script) file simply saves the duplication of effort for each compilation and is not fundamentally free.

In the process of building the final execution file from the source code of C, which is the creation of the human being and what is the machine supposed to do? Obviously, what programmers should do is:

  1. Church machine, how to compile a. c file into an. obj file.

  2. Church machine, how to link several. obj files into an. exe file.

  3. Tell the machine that your project is made up of those. c files, and eventually you want to generate a. exe file with a name.

The first two steps are common for most similar projects, so we only use the machine once. The third step is to provide a list of files and a target file name to the machine.

Writing makefile

All://must begin with    all to echo Hello World            //line must be a tab before

  

Then Gmake,over.

My gmake default only executes the first command, that is, only echo Hello world is executed. If you want to perform the subsequent foobar.exe, you must use Gmake Foobar.exe.

At the beginning of the previous article, we talked about how to compile. c files separately from the command line and link them together. In doing so, you can make the machine do the least compilation tasks for each modification. For small projects, this does not make much sense. But big projects can save us a lot of time. Keep this in mind, there is never a common optimal solution . Because the implementation of the programme itself is also cost-aware. We just need to find the most straightforward and straightforward way to do it. For example, at the beginning of the project, one can write the simplest Makefile file, and gradually improve it as the project size expands.

Separate compile and re-link this matter, people do it is more cumbersome, it teaches the machine to do, of course, will be more cumbersome. So I did not explain in the previous article. Studious students should be able to do their own, today, I also write their own plans. But before we do that, let's start by combing the understanding of make.

Make is a tool that works in very simple mode. Inside it is a table that records the dependencies between the target files. Makefile is used to describe this dependency table. For the description of the dependency table, a very simple syntax is used:

Goal: Reliance

This means that the construction of "target" relies on "dependency" to build it first. Here, both "target" and "dependency" are files in the file system, and "dependency" itself can be a "target". If the "dependent" file time is new to the "target" file time, it means that the "target" needs to be rebuilt. This build process can also be triggered if the "target" file does not exist.

A target can have multiple dependencies, which can be written in several spaces after:

Target: Rely on 1 Dependency 2 dependency 3

This has been seen many times in our previous article. There is actually another rule that we can write:

Target: Dependent 1

Target: Dependent 2

This is done in two lines, that is, each time you write "target: dependent", you add an entry in the dependency table for the dependent relationship. (for the question of dependency addition with the same name, we'll discuss it later)

As an example:

A:B C

And

A:ba:c

is equivalent in fact.

The build method for each goal is not done by the make built-in functionality, and make simply invokes several command-line scripts written on the next line of the "target" definition. Each line of command-line scripts must start with the Tab key.

Note that if you divide the target dependency into several rows, you can only have one place to define the build script.

Example:

ALL:AALL:BA:    Echo [email protected]b:    echo [email protected]

When a Makefile is run with make, it displays:

Echo Aaecho BB

Why is it? Because make will look for the first goal defined in Makefile, it is the ultimate goal of this one. Here is all. All depends on a and b two targets. Because you do not have a and B two files under your working directory, the build of A and B is triggered. And A's construction instruction is echo [email protected], [email protected] refers to the current target "a", the result is performed echo a. Similarly, the non-existence of file B, resulting in the construction of B, the implementation of Echo B.

It should be emphasized that ECHO is not a built-in feature of make. Echo is the Windows command-line directive (called the Shell directive on the *nix system). Make is faithful to the command-line instructions that are related to the description of the line in the Tab start. The goal's build success is not based on whether the target file is correctly generated. Instead, the result of the command execution is 0. Remember when learning C language, the teacher teaches you, the main function to get the correct results, you should return 0 bar. The return 0 of this main is returned to the system. Make checks to see if the command-line instruction is executed correctly by checking the return value. If you receive a return value other than 0, the entire make process is interrupted. Of course, an instruction like Echo will typically return 0.

Note that whether a target is built correctly depends only on whether the command-line directive that builds it returns 0 correctly, not whether the file is created or updated to the latest time. In a single build, each target is built at most once. This is because make makes a simple topological sort of the dependency table, and then it starts to work.

Again, we can make multiple targets dependent on the same thing:

A b:c D

is equivalent to

A:c Db:c D

Now we can see that in the Makefile, writing: definition, is actually filling in a dependency table . One at a time: add some items to the table. Make work, first read the entire file, the complete dependency table is set up, and then according to the command line specified by the target start to work, if the command line does not specify the target, the default is the first target written in Makefile.

In this way we understand that all dependency descriptions are not written in order except for the first goal definition in Makefile. Make just adds a table entry to the dependency table and does not delete it. In principle, it is not guaranteed to be built in the order of the dependent tables, and if you need a goal to be built before another goal, you need to explicitly describe the dependency.

Http://blog.codingnow.com/2008/09/replacement_of_ide_3.html

  

"Part3" This should be a divine act (zuō)

When I waited for MinGW to download, why did the whim not use NMAKE, and then after careful, careful, patient watching and not a few lines of makefile, I think I can try the following input:

NMAKE test

After that, brush brush and brush Brush Brush brush Brush, what obj, what exe have come out. Well. I want to be quiet.

Incidentally, I did not know what was installed Cygwin ... This acid is cool.

After reading the fact can refer to this practice: http://www.cnblogs.com/youngzii/p/3395055.html

"Learning record" on the Internet learning Skills exercises and learning notes and learning experiences of makefile (VS2010)

Related Article

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.