<分区>
为什么会出现以下错误
/tmp/ccuWdVB3.o: In function `test':
MyCode.c:(.text+0x1c): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
MyCode.c
#include<stdio.h>
#include<math.h>
int test(int input1)
{
int x = 8;
int z = sqrt(x);
}
int main(int argc, char * a[]) {
}
使用命令运行时:
gcc -o a.out -lm MyCode.c
但是当我运行命令的时候
gcc MyCode.c -o a.out -lm
一切正常。为什么“MyCode.c”cli 选项的顺序在这里很重要? 还是我做错了什么?