我试图编译一个需要使用"math.h"的C库,这里是.c文件的开头:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "sparse_matrix.h"
...
我用这个命令进行编译:
gcc -c ./sparse_matrix.c -o sparse_matrix.o -lm -Wall -pedantic -std=c99 -g -O
尽管我已经使用了#include
并在文件后面加上了标志-lm
(我试过把它放在行尾但没有改变),但我仍然得到以下错误:undefined reference to « sqrt »
collect2: error: ld returned 1 exit status
经过一小时的谷歌搜索,我还是不明白问题出在哪里。 我正在Ubuntu 14.10 (utopic unicorn)下使用gcc 4.9。 非常感谢您提前的任何帮助!
makefile
中不要在规则之前使用@ - 这可能不是您的问题,但它会隐藏命令并误导您。)而且大部分内容都是@paxdiablo所说的。 - Jonathan Leffler