I have a small library and recently ported some functions from C to assembly on Linux x86-64.
Then I wanted to make adoptions for macOS 15 on x86-64 but did run into an issue with nasm (installed via MacPorts).
Using a single function buffer_close() for testing here.
With C it works fine:
lib$ cc -c -o buffer_close.o buffer_close.c
lib$ cc -I. -o buffer buffer.c buffer_close.o buffer_flush.o
But when using the assembly version of the function the linker can't resolve all symbols:
lib$ nasm -I. -f macho64 -o buffer_close.o buffer_close.asm.off
lib$ cc -I. -o buffer buffer.c buffer_close.o buffer_flush.o
ld: warning: no platform load command found in '/Users/fwbrgmn/Documents/private/ngtx/lib/libfwb/lib/buffer_close.o', assuming: macOS
Undefined symbols for architecture x86_64:
"_buffer_close", referenced from:
_test_buffer_close in buffer-a2962b.o
_test_buffer_close in buffer-a2962b.o
"buffer_flush", referenced from:
buffer_close in buffer_close.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I also tried to create the object file of buffer.c and then call the linker directly:
lib$ cc -I. -c -o buffer.o buffer.c
lib$ ld -macos_version_min 15.0 -L$(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib -lSystem -o buffer buffer.o buffer_close.o buffer_flush.o
ld: warning: no platform load command found in '/Users/fwbrgmn/Documents/private/ngtx/lib/libfwb/lib/buffer_close.o', assuming: macOS
Undefined symbols for architecture x86_64:
"_buffer_close", referenced from:
_test_buffer_close in buffer.o
_test_buffer_close in buffer.o
"buffer_flush", referenced from:
buffer_close in buffer_close.o
ld: symbol(s) not found for architecture x86_64
Start of this assembly file:
lib$ head -n 12 buffer_close.asm.off
%include "buffer.inc"
section .text
global buffer_close
extern buffer_flush
buffer_close:
; rdi pointer to struct st_buffer b
; eax return 0 on success or -1 on error
push r15
push r14
What am I missing here to get symbols properly created by nasm for the usage by cc/ld?