DEV-CPPMINGW32 Environment Use static connection libraries and do your own static library

xiaoxiao2021-03-06  98

From: http://blog.9cbs.net/visioncat/ (Big Dipper's column)

Modify: Add #include "windows.h" in the first code.

------------------------------------- Use the static connection library in your program ---- --------------------------------

In Windows may be familiar with files ending with OBJ and LIB. These files are the binary and static connection libraries under Win32. But there are some special in MingW32, I originally introduced in the first chapter. They are O and A. Very strange. However, we just know how to use it. About more is not within the scope of this article. Let's take a VC as an example, you know that you want to use a static library in the VC to select the imported static library when the program is connected. The parameter is the full name of the static library. For example, WinMM.LIB but is somewhat different from mingW32. The parameter you use is -LWINMM. And -LWINMM means importing static link library libwinmm.a. Is it something wrong? Let's take a look at the use and significance in the DEV. First we start the DEV, create a new project. Then select Engineering -> Engineering Attributes. (If you use the New Look icon, the engineering property is a shield icon.) Then, select the Parameters tab. Enter the parameters you want in the text box of the connector, such as -lwinmm. As for the split, a space can be used or a carriage return. But I personally recommend the carriage return. If you are going well, your interface looks like a picture below.

Of course, if you want to use * .lib, you can fill in the file name directly. Just like WinMM.LIB. Of course, if you can use an absolute path. Let's take a look at the format of the static connection library. Of course, we are not analyzing from the file format, but from the call format. Usually the file name of the static library is lib * .a * indicates any character. And when we call, you don't need to use all the file names, just need to use * content. Just like calling libwinmm.a, we only need to add parameters when connecting - LWINMM. The front LIB and behind .a don't need it. If, don't understand. You can look at the lib directory in the DEV installation directory. There are many static connection libraries under Win32. It will be very clear about the file name and calling method. Finally, we combat the use of static connection libraries. What is it written? Write a music player on a console. Of course, just simply play music, and the path does not support Chinese. Here is just to be familiar with the use of static libraries. Create a new console project, then we write the following code in the main code of Main.c.

//main.c#include "windows.h"

#define max 255

INT Main (int Argc, char * argv []) {if (argc == 2) {char filename [max]; strcpy (filename, "open"); strcat (filename, argv [1]); strcat (filename, "Alias ​​Media"); McISendstring ("Close Media", 0, 0, 0);

McIndstring (filename, 0,0,0);

McISendstring ("Play Media", 0, 0, 0);

System ("pause");} else {printf ("Play.exe MusicFileName);

Return 0;

} // main.c end

Usage: Main filename.wav then enters -Lwinmm in the connector parameters of the engineering properties. Start compilation. If we go well, our procedure will compile success. And you can play some common music files. Happy.

Ok, this chapter we will end here with this example.

Ask the proud: Since I have been busy recently, the original two chapters changed to a chapter. please forgive. The next chapter will introduce how to establish a static connection library of MINGW32. Stay tuned. And I hope that you can give more comments. Because whether the procedure is still improving, it can be more improved through constant exchange.

------------------------------------ Make their own static link library -------- ----------------------------------

This is Chapter VII, and the eight numbers like many people like it. me too. (I feel so superstition.) This chapter we have to make a static link library, I believe that you will be very happy. First of all, I will briefly introduce the role of the static link library. We know that the C / C program generates the process of target code, write code, compile code, connection code, and generate the target code. When connecting the code, the compiled binary code is connected to the target code. However, sometimes it. We want the program to import the necessary code, and do not want to import useless code into our program. What should we do? Very simple, use a static connection library. Use it we can implement the purpose of importing the function used in the program. Let's take a step by step to do a static link library and learn how to use it. We must write a code first, you can use DEVs to use Notepads to use any text editor you like. As I prefer VI or Emacs as the usual text editor. It's far away, and now I'm passing. We write down the following code.

//Helloworld.c

#include

Void HelloWorld (Void) {Printf ("Hello World");}

The C-code should be very familiar with the C code, then the classic Hello World is good to make me miss. We started to be generated after saving for helloworld.c. First of all, let's compile helloworld.c first

gcc -c helloworld.c -o helloworld.o

This way we get a binary file helloWorld.o

Then we generate a static library.

Ar CQs Libhelloworld.a HelloWorld.o

This way our party is still a static link library. If there is a need to add another binary file name to a static link library. In addition, the generated static library file name must be Lib * .a

Ok, now let's use our library.

Next, in order to be able to use it, we write a next file.

//HelloWorld.hvoid HelloWorld (Void);

Then we start using the static library we just generated. Write a file of main.c.

//main.c

#include "HelloWorld.h"

INT main (void) {helloworld (); return (0);

Compile with GCC, assume that all of us are saved in the same directory here.

gcc -c main.c -o main.o

Then we connect the program.

gcc main.o -o main.exe -l "./" -lhelloworld

If we have successfully we get a main.exe file.

Enter main.exe or main in the console can appear Hello World.

Looking at the above article is very excited to generate your own static link library? In fact, I personally think that MingW32 generates a static link library to be simpler than VC. I don't know if you have this feeling.

Of course, if you want to use a static connection library under DEV, it is also possible. Method I have said in the previous chapter. Just, if you want to use your library, you must set the path. Just add -l "your folder for your library" in the connector parameter or save your library to the lib directory in the DEV installation directory.

Ok, this article introduces here. If you have any questions, you can leave a message here.

Ask the eucalyptus:

This article is actually really like, not the article likes, but it is very like. I don't know how you think. Here is a method of generating a static library that feels simpler than the VC generated. In fact, it is necessary to generate a dynamic connection library under the GCC's Linux platform. It is not known to be simpler than the VC. If the best platform for development in Win32 is Win2000, then the platform used to develop in the X86 system is too linux. The content of this chapter may have some strangers to many of the programmers. I really worry that you will encounter problems in practice, so I still hope that you will ask here when you encounter difficulties. Finally, my famous saying: Whether it is a procedure or thinking through constant exchanges, it can be more perfect. (I have seen "Ancient Ren Minglang"? The protagonist always likes to publish a view: I am an ancient 畑 畑 三.. I feel like him. However, this is indeed a good film. At least a lot of exploration Both good, there is no extra plot, no you, my my love. Purely taken from a case of a way of solving the case. Recommend you to see.)

转载请注明原文地址:https://www.9cbs.com/read-123853.html

New Post(0)