【问题标题】:An error when compiling C and S files together一起编译 C 和 S 文件时出错
【发布时间】:2016-11-24 19:27:43
【问题描述】:

我有这个错误:

/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/crt1.o: In function `_start':
/build/glibc-mqlSLF/glibc-2.19/csu/../ports/sysdeps/arm/start.S:119: undefined reference to `main'

当我尝试执行我的 makefile 时:

CC=gcc
CFLAGS=-I.
DEBUGFLAGS=-D NDEBUG -O3
RM=rm -f
default: all

all: fib.o bigint.o bigintadd.o
    $(CC) $(DEBUGFLAGS) -o fib fib.o bigint.o bigintadd.o

fib.o: fib.c bigint.h
    $(CC) $(DEBUGFLAGS) -c fib.c -o fib.o $(CFLAGS)

bigint.o: bigint.c bigint.h bigintprivate.h
    $(CC) $(DEBUGFLAGS) -c bigint.c -o bigint.o $(CFLAGS)

bigintadd.o: bigintadd.s bigint.h bigintprivate.h
    as -o bigintadd.o bigintadd.s $(CFLAGS)
    $(CC) $(DEBUGFLAGS) -s bigintadd.s -o bigintadd.o $(CFLAGS)



clean:
    $(RM) fib fib.o bigint.o bigintadd.o

我的 .s 文件中的“主”分支被命名为 BigInt_add,因为 .c 文件调用了这个函数。我尝试将其设为 _start 或 main,但编译器抱怨找不到 BigInt_add 分支。

任何建议为什么会发生这种情况?

【问题讨论】:

  • C 部分有main 吗? (因为我相信错误发生在链接期间,而不是编译期间,并且它与程序集无关,但是您的源代码中缺少main“入口点”..您也可以在程序集文件中定义它,但我希望它在fib.c)
  • 是的,我确实有 main in fib.c @Ped7g
  • 你们为什么要组装和编译 bigintadd.s...?
  • @TonyB 因为我对汇编和 gcc 很陌生,这可能是一个错误
  • 你做到了吗.globl?发布minimal reproducible example!

标签: c assembly makefile


【解决方案1】:

问题是我试图通过以下行来编译 .s 文件:

$(CC) $(DEBUGFLAGS) -s bigintadd.s -o bigintadd.o $(CFLAGS)

当我删除它时,问题就解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多