Usually we call the static link library is a .lib file, the file is generally large, can compile functions and data into a .lib file, then how to establish a static link in the Linux system What about the library? The following small series will introduce you to the method of establishing a static link library in Linux.
There are two main steps:
1. Compile the source code
2. Make the library
============= ===================================== Use two simple source code as an example to demonstrate the specific process of static library production
1. Compile source
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
2. Make a static library
ar -r libhello.a hello_first.o hello_second.o
Call the library instance
hello_main.c
#include "stdio.h"
void hello_first(void);
void hello_second(void);
int main()
{
Hello_first();
hello_second();
return 0;
}
Compile:
First method:< Br>
gcc hello_main.c libhello.a -o hello_main
Second method:
Copy libhello.a to /lib directory
gcc hello_main. c -lhello -o hello_main2
run shot:
OK! The static library call succeeded! !
Thinking:
What is the role of static libraries? Why invent it?
1. Static library is mainly used to facilitate programmer programming, the function to be used is packaged into a library, just tell them the function interface, so that the programmer only knows how to call it. The manufacturer can keep the interface unchanged and modify and maintain the code.
2. It is also possible that the programmer himself encapsulates the functions he often uses, without having to rewrite it, just call the declaration before you can.
The above is the introduction of Linux to establish a static link library. When making a static link library, you need to compile the source code first, and then make a static link library.
Perl is a programming language, as powerful as C, and easy to use. However, Perl co
To avoid wasting extra space on the system, it is necessary to extend the XFS file system. How do yo
When using rsync to transfer large files, Linux system cannot guarantee the complet
Linux watch is a monitoring command, used to monitor the execution of the command,
Linux prompts gzip:stdin:not when extracting tar.gz file?
Linux blocking browser request alert method on browser
How to use uniq command to delete text duplicate lines in Linux system
How to open a file in a terminal using Linux commands
Steps to set up UFW firewall on Ubuntu
How to install VPN in CentOS system
How to use the ping command to diagnose the network in Linux system
What should I do if I get an error when compiling PARSEC 2.1 under Ubuntu?
How can Ubuntu users not use the sudo command?
RedHat software source prompt Unable to read consumer identity?
How to restart Tomcat regularly on Linux system
What should I do if the Java process under Linux system disappears without cause?
Vulnerability: Causes Vista Explorer shell to crash
Win8 version of Ali Wangwang evaluation
Win7 reinstallation system tutorial
Vista system automatically manages and burns photos
Learn more about Windows XP Bring Your Own System Restore
Summary of several methods for opening the service management interface of Win7 system
GHOST use detailed explanation
How to restore system win8 Open Win8 system restore operation method