日期:2014-05-16  浏览次数:20618 次

Linux下.ko, .o, .so, .a, .la文件

Linux下文件的类型是不依赖于其后缀名的,但一般来讲:

  • .ko?是Linux 2.6内核使用的动态连接文件的后缀名,也就是模块文件,用来在Linux系统启动时加载内核模块
  • .o?是目标文件,相当于windows中的.obj文件
  • .so?为共享库,是shared object,用于动态连接的,和dll差不多
  • .a?为静态库,是好多个.o合在一起,用于静态连接
  • .la?为libtool自动生成的一些共享库,vi编辑查看,主要记录了一些配置信息。可以用如下命令查看file *.la来查看文件类型

创建.a库文件和.o库文件:
  $ gcc -c mylib.c
  $ ar -r mylib.a mylib.o

动态链接库*.so的编译与使用

1、动态库的编译?
下面通过一个例子来介绍如何生成一个动态库。这里有一个头文件,三个.c文件:

so_test.h

test_a.c

test_b.c

test_c.c

我们将这几个文件编译成一个动态库:libtest.so。

?

代码
so_test.h: #include <stdio.h> #include <stdlib.h> void test_a(); void test_b(); void test_c(); test_a.c: #include \"so_test.h\" void test_a() { printf(\"this is in test_a...\\n\"); } test_b.c: #include \"so_test.h\"