首页 > 解决方案 > GAS 32 位程序集中的未定义符号错误

问题描述

我编写了一个名为“test.s”的 GAS 32 位源代码,如下所示:

.global _main
.data
    message: .string "Hello, World!\n\0"
.text
_main:
    # BEGIN Stack Frame
    pushl %ebp
    movl %esp, %ebp

    # Call Unix System Call - write(fd, buf, count)
    pushl $1 # fd = stdout
    pushl $message # buf = message
    pushl $14 # count = 14
    call write

    # END Stack Frame
    movl %ebp, %esp
    popl %ebp

    xor %eax, %eax # return 0
    ret

我在 macOS 10.14.4 (Mojave) 中运行如下命令:

$ gcc -m32 test.s -otest

然后出现错误:

ld: warning: The i386 architecture is deprecated for macOS (removed from the Xcode build setting: ARCHS)
ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd, missing required architecture i386 in file /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd
Undefined symbols for architecture i386:
    "write", referenced from:
    _main in test-8c5cf2.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

但具体是什么原因我也不知道...

标签: macosassemblygnu-assembler

解决方案


推荐阅读