gcc Link order of libraries
来源:互联网 发布:淘宝助理软件手机版 编辑:程序博客网 时间:2024/06/11 19:23
URL :http://www.network-theory.co.uk/docs/gccintro/gccintro_18.html
2.7.1 Link order of libraries
The traditional behavior of linkers is to search for external functions from left to right in the libraries specified on the command line. This means that a library containing the definition of a function should appear after any source files or object files which use it. This includes libraries specified with the short-cut -l option, as shown in the following command:
$ gcc -Wall calc.c -lm -o calc (correct order)
With some linkers the opposite ordering (placing the -lm option before the file which uses it) would result in an error,
$ cc -Wall -lm calc.c -o calc (incorrect order)
main.o: In function `main':
main.o(.text+0xf): undefined reference to `sqrt'
because there is no library or object file containing sqrt after ‘calc.c’. The option -lm should appear after the file ‘calc.c’.
When several libraries are being used, the same convention should be followed for the libraries themselves. A library which calls an external function defined in another library should appear before the library containing the function.
For example, a program ‘data.c’ using the GNU Linear Programming library ‘libglpk.a’, which in turn uses the math library ‘libm.a’, should be compiled as,
$ gcc -Wall data.c -lglpk -lm
since the object files in ‘libglpk.a’ use functions defined in ‘libm.a’.
Most current linkers will search all libraries, regardless of order, but since some do not do this it is best to follow the convention of ordering libraries from left to right.
This is worth keeping in mind if you ever encounter unexpected problems with undefined references, and all the necessary libraries appear to be present on the command line.
- gcc Link order of libraries
- DLL(Dynamic Link Libraries)
- DLL(Dynamic Link Libraries)
- Dynamic Link Libraries
- DLL(Dynamic Link Libraries)
- DLL(Dynamic Link Libraries)
- DLL(Dynamic Link Libraries)
- DLL(Dynamic Link Libraries)
- [link]Useful Libraries
- GCC Link
- The order of GCC's options DOES matter under windows.
- ADS之Link order
- DLL(Dynamic Link Libraries)专题
- DLL(Dynamic Link Libraries)专题
- DLL(Dynamic Link Libraries)专题
- DLL(Dynamic Link Libraries)专题
- DLL(Dynamic Link Libraries)专题
- DLL(Dynamic Link Libraries)专题
- HeadFirst Strategy策略模式
- SHA1算法原理
- flash加载html代码
- Java嵌入式数据库berkeleyDB(一)
- Java嵌入式数据库berkeleyDB(二)
- gcc Link order of libraries
- 酒店管理系统需求分析
- 什么是AT Command Set?
- 解析word文档2
- 第4章 让操作系统走进保护模式
- 整理:.NET 性能优化方法总结
- 读Windows核心编程 - 13
- 马化腾关于产品设计与用户体验的培训摘要
- 完整ASCII码对照表