深入理解:C 与汇编语言函数的结合使用
1. 静态库编译
当静态库文件创建完成后,就可以用它来编译那些需要库中任意函数的 C 程序。以下是具体的示例命令:
$ gcc –o intttest inttest.c libchap14.a
$ gcc –o stringtest stringtest.c libchap14.a
$ gcc –o floattest floattest.c libchap14.a
使用该库编译程序不会影响生成的可执行文件大小。可以通过比较仅使用单个函数目标文件和使用静态库文件的编译结果来验证:
$ gcc -o inttest inttest.c square.o
$ ls -al inttest
-rwxr-xr-x 1 rich rich 13838 Sep 22 16:36 inttest
$ gcc -o inttest inttest.c libchap14.a
$ ls -al inttest
-rwxr-xr-x 1 rich rich 13838 Sep 22 16:37 inttest
从上述结果可以看出,生成的文件大小完全相同,且运行结果也一致。
2. 共享库的使用
2.1 什么是共享库
在使用静态库编译应用程序时,函数代码会被编译到应用程序中,这意味着应用程序所需的所有代码都位于可执行程序文件内。但这种方式存在一些缺点:
超级会员免费看
订阅专栏 解锁全文
126

被折叠的 条评论
为什么被折叠?



