How to set up static link library .lib file by Linux
This article mainly explains "Linux how to build static link library .lib file", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Linux how to build static link library .lib file" bar!
There are two main steps:
1. Compile source code
two。 Production library
= =
Take two simple source codes as examples to demonstrate the specific process of making static libraries.
1. Compile source code
Hello_first.c
Void hello_first (void)
{
Printf ("hello first")
}
Hello_second.c
Void hello_second (void)
{
Printf ("hello second")
}
Compile:
Gcc-c hello_first.c-o hello_first.o
Gcc-c hello_second.c-o hello_second.o
two。 Make a static library
Ar-r libhello.a hello_first.o hello_second.o
Specific instance of calling library
Hello_main.c
# include "stdio.h"
Void hello_first (void)
Void hello_second (void)
Int main ()
{
Hello_first ()
Hello_second ()
Return 0
}
Compile:
The first method:
Gcc hello_main.c libhello.a-o hello_main
The second method:
Copy libhello.a to / lib directory
Gcc hello_main.c-lhello-o hello_main2
Run the screenshot:
OK! Static library call succeeded!
Think about:
What is the function of static library? Why invent it?
1. Static libraries are mainly used to facilitate programmers' programming, and the functions to be used are encapsulated into libraries. Just tell them the function interface, so the programmer only needs to know how to call it. The manufacturer can keep the interface unchanged and modify and maintain the code.
two。 In addition, it is possible that programmers encapsulate the functions they often use, so that they don't have to write them repeatedly, just declare them before calling.
Thank you for reading, the above is the content of "Linux how to build static link library .lib file". After the study of this article, I believe you have a deeper understanding of how Linux establishes static link library .lib file, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!