Static Libraries
来源:互联网 发布:杨辉三角1~9c语言程序 编辑:程序博客网 时间:2024/06/05 16:03
bill.c:
#include<stdio.h>
void main(char *arg)
{
printf("bill:we passed %s\n",arg);
}
fred.c:
#include<stdio.h>
void fred(int argc)
{
printf("fred:we pass %d\n",arg);
}
$ gcc -c bill.c fred.c
$ ls *.olib.h:
void bill(char*);
vodi fred(int);
program.c:
#include<stdlib.h>
#include"lib.h"
int main()
{
bill("Hello world!");
}
gcc -c program.c
$ gcc -o program program.o bill.o
$ ./program
bill: we passed Hello Worldcreat your own static library file:
Now you’ll create and use a library. Use the ar program to create the archive and add your object files to it. The program is called ar because it creates archives, or collections, of individual files placed together in one large file. Note that you can also use ar to create archives of files of any type. (Like many UNIX utilities, ar is a generic tool.)
$ ar crv libfoo.a bill.o fred.o$ranlib libfoo.a
$ gcc -o program program.o libfoo.a
$./program program.o libfoo.a
$./program
You could also use the –l option to access the library, but because it is not in any of the standard places,you have to tell the compiler where to find it by using the –L option like this:
$ gcc –o program program.o –L. –lfoo
The –L. option tells the compiler to look in the current directory (.) for libraries. The –lfoo option tells the compiler to use a library called libfoo.a (or a shared library, libfoo.so, if one is present). To see which functions are included in an object file, library, or executable program, you can use the nm com-mand. If you take a look at program and lib.a, you see that the library contains both fred and bill,but that program contains only bill. When the program is created, it includes only functions from the
library that it actually needs. Including the header file, which contains declarations for all of the func-tions in the library, doesn’t cause the entire library to be included in the final program.
- Static Libraries
- Static Libraries in Xcode
- Static and dynamic libraries
- Linker Use static Libraries
- Creating Static Libraries For iOS
- MinGW Static and Dynamic Libraries
- Static, Shared Dynamic and Loadable Linux Libraries
- Duplicate symbols when linking ObjectiveC static libraries
- GCC compiler static libraries and dynamic library
- Building Objective-C static libraries with categories
- Py_Initializemisses necessary libraries (static libpython.a)
- Static, Shared Dynamic and Loadable Linux Libraries
- Static, Shared Dynamic and Loadable Linux Libraries
- Building Objective-C static libraries with categories
- Xcode Multiple Static Libraries and Duplicate Symbols
- Objective-C static libraries with categories
- 在动态库(dynamic libraries)和静态库(static libraries)使用模板(template)
- Tutorial: Code Sharing Via Static Libraries And Cross-Project References
- Java中的String
- 内部类+迭代器模式
- 三菱FX1s中STL语句问题
- ListView控件
- Android 4.0 Launcher源码分析系列(二)
- Static Libraries
- java remote
- 24、Android应用-找一个朋友 (整合SQLite/Content Provider/Google Maps)
- Android 4.0 Launcher源码分析系列(三)
- C#的三种设计模式
- pull解析
- 爵士、古典、摇滚、流行音乐
- Servlet总结
- 在ubuntu中安装Adobe Acrobat Reader