gcc参数-l传递顺序错误导致`undefined reference'的一点小结
2014-11-04 20:46
274 查看
刚才编译一个pthread的单文件程序, 使用的命令行是:
gcc -o thread1 -lpthread thread1.c
结果报错:
仔细看了一下, 代码编译过了, 链接的时候出的错. 但pthread库是真实存在的.
而且gcc的语法是:
Usage: gcc [options] file...
是我平常最喜欢的传参方式, 也是按规定的方式传入的, 咋个就不行了呢? 不带这样玩的!
仔细看了看, 发现一个 `-v --help' 的选项, 于是 gcc -v --help, ~!@#$%^&
输出结果将近3000行!!!, 吓尿~~~~~~~
没办法, Google之, 得到了相关说明:
1. Link order of libraries
2. C++ shared library - undefined reference
解决办法:
把对库的引用放在源文件后面, 因为那是传给链接器的参数!
要改成这样:
gcc -o thread1 thread1.c -lpthread
女孩不哭 @ cnblogs.com/memset @ 2014.11.04
gcc -o thread1 -lpthread thread1.c
结果报错:
$ gcc -o thread1 -lpthread thread1.c /tmp/ccNqs6Bh.o: In function `main': thread1.c:(.text+0x49): undefined reference to `pthread_create' thread1.c:(.text+0x5f): undefined reference to `pthread_join' collect2: error: ld returned 1 exit status
仔细看了一下, 代码编译过了, 链接的时候出的错. 但pthread库是真实存在的.
而且gcc的语法是:
Usage: gcc [options] file...
是我平常最喜欢的传参方式, 也是按规定的方式传入的, 咋个就不行了呢? 不带这样玩的!
仔细看了看, 发现一个 `-v --help' 的选项, 于是 gcc -v --help, ~!@#$%^&
输出结果将近3000行!!!, 吓尿~~~~~~~
没办法, Google之, 得到了相关说明:
1. Link order of libraries
2. C++ shared library - undefined reference
解决办法:
把对库的引用放在源文件后面, 因为那是传给链接器的参数!
要改成这样:
gcc -o thread1 thread1.c -lpthread
女孩不哭 @ cnblogs.com/memset @ 2014.11.04
相关文章推荐
- 存储过程传递参数与表中字段属性相同导致错误
- gcc参数错误导致的makefile错误
- 【GCC】参数顺序导致的“undefined reference”问题
- 动态传递参数到DevExpress.XtraReports的小结
- 存储过程传递参数时出现类型转换错误!如:varchar转换为int时出错
- jsp传递中文参数、空格以及表单内容换行问题解决小结
- 传递相同的参数多次而导致的混淆(Oracle)
- ASP.Net处理QueryString函数汉字参数传递错误
- gcc的编译连接参数也是讲究排列顺序的
- 由于错误传入Marshal.GetTypedObjectForIUnknown参数导致的应用程序crash
- 水晶报表中关于参数导致的错误
- C语言常见错误小结 ( 希望对c语言爱好者有一点帮助)
- 关于ASP.NET中Resonse.QueryString函数汉字参数传递错误的处理办法
- ASP.Net处理QueryString函数汉字参数传递错误
- 杂:表达式计算顺序,参数传递顺序,typedef和define一个区别
- [Remoting FAQ]传递Remoting参数时遇到的两种常见错误
- gcc优化导致的错误
- [导入]动态传递参数到DevExpress.XtraReports的小结
- GCC版本不兼容导致的链接错误:undefined reference to `SomeFunction'
- Intel和ARM GCC程序函数调用的参数传递