Dev-CPP/mingw32 Environment Introduction (5)

Source: Internet
Author: User

Dev-CPP/mingw32 Environment Introduction (5)

Review above:

In the previous section "Dev-CPP/mingw32 Environment Introduction (4)", we introduced how to use static connection libraries. Today, we will introduce how to create your own mingw32 static Link Library. For the static Connection Library under Win32, I 'd like to know how to make it. So we will not introduce it here.

 

Chapter 8 create your own static Link Library

This is Chapter 8, which many people like. The same is true for me. (I feel so superstitious .) We are going to create a static link library in this chapter. I believe you will be very happy.
First, I will briefly introduce the role of the static Link Library. We know that C/C ++ProgramGenerate targetCodeThe process includes writing code, compiling code, connecting code, and generating target code. When connecting code, the compiled binary code is connected to the target code. However, sometimes. We want the program to import the necessary code, instead of importing useless code into our program. What should we do? It's easy to use a static Connection Library. With this function, we can import the functions used in the program.
Next we will learn how to use static link libraries step by step.
Now let's write a piece of code. You can use Dev, notepad, or any text editor you like. For example, I prefer VI or Emacs as the usual text editor. It's far from saying anything. Let's write down the following code.

// Helloworld. c

# Include <stdio. h>

Void helloworld (void)
{
Printf ("Hello World ");
}

The above section of the C code should be very familiar to you, so the classic Hello world makes me miss it. After saving it as helloworld. C, we will start to generate it.
First, compile helloworld. C.

Gcc-C helloworld. C-o helloworld. o

In this way, we get a binary file helloworld. O.

Then we generate a static library.

Ar cqs libhelloworld. A helloworld. o

In this way, we can use the static Link Library. If necessary, you can add other binary file names to the end of helloworld. O and link them to a static Link Library. In addition, the generated static library file name must be lib *.

Now let's use our library.

Next, we will write the following header file for ease of use.

// Helloworld. h
Void helloworld (void );

Then we start to use the static library we just generated. Write a main. c file.

// Main. c

# Include "helloworld. H"

Int main (void)
{
Helloworld ();
Return (0 );
}

Compile with GCC. Assume that all the files are saved in the same directory.

Gcc-C main. C-o main. o

Then we connect to the program.

GCC main. O-o main.exe-L "./"-lhelloworld

If we are successful, we will get a main.exe file.

Input main.exe or main under the console to display the hello World Group words.

Read the aboveArticleAre you excited to generate your own static Link Library? In fact, I personally think that the static Link Library generated by mingw32 is simpler than that generated by VC. I wonder if you feel like this.

Of course, if you want to use a static Connection Library Under Dev, you can also. Methods I have already mentioned in the previous chapter. However, if you want to use your own library, you must set the path.

Just add-L "the folder where your library is located" to the connector parameters or save your library to the lib directory in the dev installation directory.

Now, this article will introduce you here. If you have any questions, leave a message here.

Question:

I really like this article, not the article, but the content. I don't know what you think. This section describes how to generate a static library, which is easier to generate than VC. In fact, it is much easier to generate a dynamic connection library on the GCC Linux platform than to generate a dynamic Connection Library under VC. If Win2000 is the best platform for development in Win32, Linux is the only platform for development in x86 systems. The content of this chapter may be unfamiliar to many programmers. I am really worried that you will encounter problems in practice, so I hope you will ask more questions here when you encounter difficulties. My last sentenceFamous saying: Programs and ideas can be improved only through continuous communication. (Have you read "Gu Yi Ren sanlang? After posting his point of view, the main character always likes to say: I am Ren sanlang of Gu Yi. I feel like him too. However, this is indeed a good film. At least it is better than many domestic spying films. There is no additional plot, no love between you and me. It was taken purely from the perspective of solving the case. We recommend that you take a look .)

 

Studio software development team

Dipper (Huang yaokui)

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.