gcc参数-l传递顺序错误导致`undefined reference'的一点小结
刚才编译一个pthread的单文件程序, 使用的命令行是:
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 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参数-l传递顺序错误导致`undefined reference'的一点小结的更多相关文章
- 由于link顺序错误导致的undefined reference
其实我之前就遇到过这个问题,也强调过,GNU-G++在link阶段是依赖输入的.o或者.a文件的顺序的.如果顺序错误会导致undefined reference错误 见这篇随笔:http://www. ...
- 错误:undefined reference to `__gxx_personality_v0'
使用gcc编译C代码,引用了C++ 库,出现这个错误,网上搜到这哥们的文章,解决问题 转自:错误:undefined reference to `__gxx_personality_v0' 1. Li ...
- Qt错误:类中使用Q_OBJECT宏导致undefined reference to vtable for "xxx::xxx"错误的原因和解决方法
在进行Qt编程的时候,有时候会将类的定义和实现都写在源文件中,如果同时在该类中使用信号/槽,那么可能就会遇到 undefined reference to vtable for "xxx:: ...
- GCC编译uboot出现(.ARM.exidx+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'错误的解决的方法
/opt/arm-2010.09/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.1/armv4t/libgcc.a(_bswapsi2.o):(.ARM.exid ...
- Linux下编译C++程序遇到错误:undefined reference to `*::*
“undefined reference to”的意思是,该函数未定义. 如果使用的是g++,有以下检查方案: 如果提示未定义的函数是某个库的函数.检查库是否已经安装,并在编译命令中采用-l和-L参数 ...
- 【错误】undefined reference to `boost::....的解决
很多新手引用Boost库编程,在ubuntu下编译时候有时候会出现如下错误: test04.cpp:(.text+0x2c): undefined reference to `boost::progr ...
- C++(2):错误:undefined reference to `__gxx_personality_v0'
1. Linux Develop Notes * 编译 c++ 程序需要添加 -lstdc++ sample: gcc -lstdc++ -o test test.c,否则会报 " ...
- C++函数参数的传递顺序
C++编译器默认使用的是 __cdecl 模式,参数是通过栈传递的,因此是从右到左的传参顺序. int f(int a, int b, int c) { return 0; } int main(){ ...
- QT编译错误:undefined reference to `__imp_gl*'等等
学习QT OpenGL绘制图形,程序中使用了OpenGL的API函数(gl开头),但是编译出现了错误:截图如下 有过编程经验的人可知,是链接的时候出错,找不到函数的实现! 解决方法:在工程*.pro文 ...
随机推荐
- HDU 1083 网络流之二分图匹配
http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #inc ...
- HDU 2861 四维dp打表
Patti and Terri run a bar in which there are 15 stools. One day, Darrell entered the bar and found t ...
- Linux nohup 程序后台运行
&方式: Unix/Linux下一般想让某个程序在后台运行,很多都是使用 & 在程序结尾来让程序自动运行.比如我们要运行mysql在后台: /usr/local/my ...
- 【云计算】docker前世今生
下一代云计算模式:Docker正掀起个性化商业革命 作者: 吴宁川 来源: ITValue 发布时间: 2015-09-20 10:41 阅读: 12976 次 推荐: 24 ...
- SQL Server中的索引
1 SQL Server中的索引 索引是与表或视图关联的磁盘上结构,可以加快从表或视图中检索行的速度.索引包含由表或视图中的一列或多列生成的键.这些键存储在一个结构(B 树)中,使 SQL Serve ...
- Walls and Gates
You are given a m x n 2D grid initialized with these three possible values. -1 - A wall or an obstac ...
- svn迁移到git仓库并保留commit历史记录
svn迁移到git仓库并保留commit历史记录 最近在做svn迁移到gitlab,由于之前一直是由svn做版本控制.最简单的方式是将svn的内容export出来,然后添加到gitlab即可.但是,如 ...
- poj1177
题意:在平面直角坐标系内给出一些与坐标轴平行的矩形,将这些矩形覆盖的区域求并集,然后问这个区域的周长是多少.(边与边重合的地方不计入周长) 分析:线段树.曾经做过类似的求矩形覆盖的总面积的题.这道题同 ...
- 解读Unity中的CG编写Shader系列二
转自 http://www.itnose.net/detail/6095974.html 上一篇文章的例子中我们可以看到顶点着色器的输出参数可以说是直接作为了片段着色器的形参传递过来,那么不由得一个问 ...
- gtk+-3.21.4 static build step in windows XP
In recent days the weather is very hot Unable to sleep properly Under the state of daze research gtk ...