アセンブラ用の静的ライブラリを作成しようとしています。しかし、それは機能していません。ライブラリは正常にビルドされますが、プログラムをビルドしようとすると、次のようになります。
$ 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
何が起こっているのか分かりますか?
私のコード:
こんにちは。
#; This is a hello world program, in assembler.
.extern exit
.data
message:
.byte 14
.ascii "Hello, World!\n"
.text
.global _start
_start:
#; First, write the message.
mov $4, %eax #; write syscall number
mov $1, %ebx #; stdout file descriptor
mov $message+1, %ecx #; message address
mov message, %dl #; we only want one byte, so %dl
int $0x80
#; Now, we need to exit.
call exit
こんにちは/メイクファイル
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
myasm.s
#; lib.s
.text
.global exit
exit:
mov $1, %eax #; exit syscall #
mov $0, %ebx #; success
int $0x80
myasm/メイクファイル
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