尝试将c main 与汇编函数链接时找不到入口符号_start

问题描述 投票:0回答:1

可以阅读汇编,但试图学习在其中编写小函数,但我似乎无法链接用 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
c linux assembly gnu-assembler
1个回答
0
投票

gcc 中的那些 fing 通常在 spec 文件中定义。您可以使用

-dumpspecs
命令行选项查看默认文件。

© www.soinside.com 2019 - 2024. All rights reserved.