Linux 工具

❑ GCC: The GNU Compiler Collection, containing the GNU C compiler
❑ G++: A C++ compiler, included as part of GCC
❑ GDB: A source code–level debugger
❑ GNU make: A version of UNIX make
❑ Bison: A parser generator compatible with UNIX yacc
❑ bash: A command shell
❑ GNU Emacs: A text editor and environment

 

 

创建.o文件

$ gcc -c bill.c fred.c
$ ls *.o
bill.o fred.o

 

建一个头文件

/*
This is lib.h. It declares the functions fred and bill for users
*/
void bill(char *);
void fred(int);

 

使用lib.h

#include “lib.h”
int main()
{
bill(“Hello World”);
exit(0);
}

 

创建.a静态库

$ ar crv libfoo.a bill.o fred.o
a - bill.o
a - fred.o

$ ranlib libfoo.a

 

编译文件

$ gcc –o program program.o –L. –lfoo

 

创建动态库

gcc -shared -Wl,-soname,your_soname  -o library_name file_list library_list

例子

gcc -fPIC -g -c -Wall a.c

gcc -fPIC -g -c -Wall b.c

gcc -shared -Wl,-soname,libmystuff.so.1  -o libmystuff.so.1.0.1 a.o b.o -lc

 

安装动态库

ldconfig -n directory_with_shared_libraries

export LD_LIBRARY_PATH=/usr/local/my_lib:$LD_LIBRARY_PATH