Undefined reference to
来源:互联网 发布:淘宝待收货p图教程 编辑:程序博客网 时间:2024/05/19 03:18
http://space.itpub.net/2008/viewspace-45218
在C++代码中调用C的库文件,需加上extern "C",用来告知编译器:这是一个用C写成的库文件,请用C的方式连接他们。
Undefined reference to 错误:这类错误是在连接过程中出现的,
可能有两种原因∶
一是使用者自己定义的函数或者全局变量所在源代码文件,没有被编译、连接,或者干脆还没有定义,
这需要使用者根据实际情况修改源程序,给出全局变量或者函数的定义体;
二是未定义的符号是一个标准的库函数,在源程序中使用了该库函数,
而连接过程中还没有给定相应的函数库的名称,或者是该档案库的目录名称有问题.
http://www.cnblogs.com/hillywolf/archive/2006/03/18/353071.html
这两天在Linux下用Eclipse编数据结构,还有试用CPPUNIT,总是遇到一个错误,
就是“undefined reference to [function name]”。
找了很久,终于发现是在写makefile的疏忽所致。
出错的时候是这样的:
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->1 main:main.o Array.o
2 g++ main.o -o main
3 ./main
4 main.o:main.cpp Array.h
5 g++ -c main.cpp
6 Array.o: Array.cpp Array.h
7 g++ -c Array.cpp
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->1 main:main.o Array.o
2 g++ main.o -o main
3 ./main
4 main.o:main.cpp Array.h
5 g++ -c main.cpp
6 Array.o: Array.cpp Array.h
7 g++ -c Array.cpp
后来才发现第二行编译的时候没有加上Array.o,把它加上就可以了。
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->1 main:main.o Array.o
2 g++ main.o Array.o -o main
3 ./main
4 main.o:main.cpp Array.h
5 g++ -c main.cpp
6 Array.o: Array.cpp Array.h
7 g++ -c Array.cpp
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->1 main:main.o Array.o
2 g++ main.o Array.o -o main
3 ./main
4 main.o:main.cpp Array.h
5 g++ -c main.cpp
6 Array.o: Array.cpp Array.h
7 g++ -c Array.cpp
这个“undefined reference to ”一般是在找不到相应的库文件的时候产生的,
没有加入Array.o也算是没有找到库文件的一种。
有时可能需要在编译选项里加入"_lLIBNAME",来指定要加入的库文件。
- undefined reference to 'floor'/undefined reference to `&
- undefined reference to 'floor'/undefined reference to
- undefined undefined reference to `nfq_open'
- undefined reference to 'pthread_create'
- undefined reference to `_Unwind_Resume'
- undefined reference to `__ctype_b'
- undefined reference to rpl_malloc
- undefined reference to '__ctype_b'
- undefined reference to `__assert_fail'
- undefined reference to 'pthread_create'
- undefined reference to `__aeabi_unwind_cpp_pr0'
- undefined reference to `cvCreate2DHMM
- undefined reference to 'getfilecon'
- undefined reference to `__gxx_personality_v0'
- undefined reference to 'pthread_create'
- undefined reference to `sin'
- undefined reference to rpl_malloc
- undefined reference to `pthread_create'
- 使用mapred寻找图中的三角形
- iPhone程序中将内容分享到新浪微博
- ListView滑动时变黑
- hadoop datanode 重新启动和hbase regionserver重新启动
- C语言复习3
- Undefined reference to
- Android开启闪光灯的几种办法
- java 之 Lock 同步锁学习示例
- 关于字符的分类,从ctype中能够挖掘出来
- C语言小作业
- 编程语言API性能大比拼
- JavaScript
- c语言作业2
- [wp7游戏]wp7经典好玩游戏~~~集合帖~~~