So I'm trying to assemble this piece of 16bit assembly code on my Mac (Monterey):
global _main
section .text
_main:
mov ah, 0x0e
mov al, '!'
int 0x10
mov ah, 0x4c
int 0x21
I am using the NASM assembler, and have so far managed to get it assembled into a .com file using the following command:
nasm testing.asm -o test.com -f bin
However when trying to link this into an executable using LD with the following command:
ld -e _main -static -o test test.com -arch x86_64
it comes up with the error:
standing-x86_64 but attempting to link with file built for
unknown-unsupported file format ( 0xB4 0x0E 0xB0 0x21 0xCD 0x10 0xB7
0x0E 0xB5 0x0E 0xB6 0x0E 0xBE 0x0E 0x00 0xBF ) Undefined symbols for
architecture x86_64: "_main", referenced from:
-u command line option ld: symbol(s) not found for architecture x86_64 ```
Does anyone know how to fix this?
Related
I am trying to use MacBook Air 2022 compile a package. However, when I compiled the Makeile, the error of Undefined symbols for architecture arm64 responsed. I looked for many resolutions but all unhelpful.
The Makefile as follow:
CC = gcc-12 -Os -fopenmp
CFLAGS = -L/usr/local/sac/lib -lsac -lsacio -lm
BIN = ../bin
FDTCC: FDTCC.o sacio.o
${CC} -o ${BIN}/$# $^ ${CFLAGS}
clean:
rm -f \*.o
the whole error as follow:
gcc-12 -Os -fopenmp -o ../bin/FDTCC FDTCC.o sacio.o -L/usr/local/sac/lib -lsac -lsacio -lm
ld: warning: ignoring file /usr/local/sac/lib/libsac.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
ld: warning: ignoring file /usr/local/sac/lib/libsacio.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
Undefined symbols for architecture arm64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
make: *** [FDTCC] Error 1
My gcc version as follow:
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Could anyone tell me how to slove this error, thanks.
I tried to assemble a Hello World but ld is throwing me a couple of errors.
Hello World:
section .data
msg db "Hello world",10
section .text
global _start
_start:
mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, 13
syscall
mov rax, 60
mov rdi, 0
syscall
nasm & ld:
nasm -f elf64 main.asm
ld main.o -o main
ld gives me these errors:
ld: warning: platform not specified
ld: warning: -arch not specified
ld: warning: No platform min-version specified on command line
ld: warning: ignoring file main.o, building for -unknown but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
Undefined symbols for architecture unknown:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture unknown
I tried using nasm with macho64
nasm -f macho64 main.asm
and got the following errors from ld:
ld: warning: alignment (1) of atom '_start' is too small and may result in unaligned pointers
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
Thanks in advance
I have problem with compilation .asm file on macOS can somebody help me?
Here is my repository:
https://github.com/ondrej-111/Asm.git
I tried to compile it with this commands:
nasm -f elf -d macho64 asm_io.asm
nasm -f elf prvy.asm
gcc -c driver.c
gcc -o prvy driver.o prvy.o asm_io.o
but I always get the same error:
ld: warning: ld: warning: ignoring file asm_io.o, file was built for
unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture
being linked (x86_64): asm_io.oignoring file prvy.o, file was built
for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the
architecture being linked (x86_64): prvy.o
Undefined symbols for architecture x86_64: "_asm_main", referenced
from:
_main in driver.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 searched some similar issues but any one helped me to fix it.( I tried this - How can I run this assembly code on OS X?)
I'm using a Macbook pro with Yosemite. Can't get the printf to work. Here's my code:
extern _printf
global _main
section .data
msg: db "Hello World"
section .text
_main:
push msg
call _printf
add esp, 4
ret
Using:
nasm -f macho test.s && gcc -arch i386 -e _main test.o && ./a.out
Output:
ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _main from test.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
Segmentation fault: 11
I'd really appreciate any help.
This answered my question perfectly! How to print argv[0] in NASM?
I have the following file hello.asm:
section .text
global _start ;must be declared for linker (ld)
_start: ;tells linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'Hello, world!', 0xa ;our dear string
len equ $ - msg ;length of our dear string
On mac, how would i turn it into a .o file. On linux i would do
nasm -f elf64 -o hello.o hello.asm
ld -o hello hello.o
then it could be called with
./hello
I have already installed Xcode and MacPorts, Thanks
Using:
nasm -o hello.o hello.asm
should work, that is, to produce an .o file. typically on OS X you do something such as:
nasm -f macho -o hello.o hello.asm