Assembly 我能';t在汇编程序中导入符号

Assembly 我能';t在汇编程序中导入符号,assembly,x86,static-libraries,unix-ar,Assembly,X86,Static Libraries,Unix Ar,我正试图为汇编程序编写一个静态库。但它不起作用。库构建得很好,但当我尝试构建程序时,会发生以下情况: $ ld -o hello -L../myasm -lmyasm hello.o hello.o: In function `_start': (.text+0x18): undefined reference to `exit' 我四处摸索,这让我更加困惑 $ nm ../myasm/libmyasm.a myasm.o: 00000000 T exit $ nm hello.o 00000

我正试图为汇编程序编写一个静态库。但它不起作用。库构建得很好,但当我尝试构建程序时,会发生以下情况:

$ ld -o hello -L../myasm -lmyasm hello.o
hello.o: In function `_start':
(.text+0x18): undefined reference to `exit'
我四处摸索,这让我更加困惑

$ nm ../myasm/libmyasm.a
myasm.o:
00000000 T exit
$ nm hello.o
00000000 T _start
         U exit
00000000 d message
知道发生了什么吗

我的代码:

你好,s hello/Makefile 我的妈妈 myasm/Makefile
hello
的Makefile中,将对象文件
hello.o
移动到
-lmyasm
之前,如下所示:

hello: hello.o
        ld -o hello hello.o -L../myasm -lmyasm
...
有关如何搜索符号,请参见此处的
-l
参考:

在命令中写入此选项的位置会有所不同;链接器在中搜索和处理库和对象文件 指定它们的顺序。因此,
foo.o-lz bar.o
搜索库
z
在文件
foo.o
之后,但在
bar.o
之前。如果
bar.o
指的是
z
,这些函数可能无法加载


尝试使用
gcc
而不是
ld
。“你没有提到你正在使用的工具,这使得你不可能给出一个明确的答案。”Gene我发布了我的Makefiles。
hello: hello.o
        ld -o hello -L../myasm -lmyasm hello.o
hello.o: hello.s
        as -o hello.o hello.s
run: hello
        ./hello
clean:
        rm hello.o hello
#; lib.s

.text
.global exit

exit:
    mov $1, %eax #; exit syscall #
    mov $0, %ebx #; success
    int $0x80
libmyasm.a: myasm.o
        ar cr libmyasm.a myasm.o
myasm.o: myasm.s
        as -o myasm.o myasm.s
clean:
        rm myasm.o libmyasm.a
hello: hello.o
        ld -o hello hello.o -L../myasm -lmyasm
...
-llibrary
-l library