Ubuntu 11.10 上的 c 数学链接器问题 [英] c math linker problems on Ubuntu 11.10
问题描述
将我的 Ubuntu 从 (10.11, 11.04 i don't know)
升级到 11.10 后,出现了一些奇怪的错误.
Some strange error appeared after I upgraded my Ubuntu from (10.11, 11.04 i dont know)
to 11.10.
我在使用 math.h 并与 -lm 链接
I am getting an undefined reference to 'sqrt'
while using math.h and linking with -lm
我正在编译 gcc -Wall -Werror -g -Iinclude/-lm lib/matrix.c src/analysis.c -o bin/analysis.o
源文件使用和包括 math.h.
I'm compiling with gcc -Wall -Werror -g -Iinclude/ -lm lib/matrix.c src/analyse.c -o bin/analyse.o
both source-files use and include math.h.
这段代码编译没有问题,升级后我没有太大变化,但现在它不起作用了.
This code compiled without problems for and I didn't change much since the upgrade but now it won't work.
你有什么建议我可以做什么来找出错误吗?
Do you have any suggestions what I can do, to find the error?
对不起,如果之前有人问过这个问题;关于数学链接器错误的帖子太多了,但我没有找到匹配的
I'm sorry, if this question was asked before; there are so many posts on math linker errors and I didn't find a matching one
推荐答案
当你从命令行使用它时,你正在使用的库需要放在使用它的文件之后.因此,将 -lm
放在命令行上的 C 文件之后.
The library that you are using needs to be placed after the files that use it when you are using it from the command line. So place -lm
on after your C files on the command line.
这篇关于Ubuntu 11.10 上的 c 数学链接器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!