可以阅读汇编,但试图学习在其中编写小函数,但我似乎无法链接用 C 编写的 main 调用用 Gas 编写的 extern 函数。目标是linux x64。
这是 main.c:
#include <stdio.h>
extern int somefunc();
int main() {
int x = somefunc();
printf("returned %d\n", x);
return 0;
}
这里是 sf.s:
.global somefunc
.data
.text
somefunc:
movl $123, %eax
ret
以下是编译命令:
> gcc -c -fno-pie main.c -o main.o
> as sf.s -o sf.o
> ld -lc main.o sf.o -o m
ld: warning: cannot find entry symbol _start; defaulting to 0000000000401020
gcc 中的那些 fing 通常在 spec 文件中定义。您可以使用
-dumpspecs
命令行选项查看默认文件。