nasm and ld: xxx not specified for Mac OS Ventura - macos

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

Related

How to solve the Error of Undefined symbols for architecture arm64 when compiling use gcc

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.

How do I compile my 16 bit Mac assembly code?

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?

macOS assembly, cannot use str() command [duplicate]

This question already has answers here:
What is the meaning of MOV (%r11,%r12,1), %edx?
(2 answers)
How is $example different from example(%rip)?
(1 answer)
Closed 4 years ago.
I have been following this tutorial and have got stuck at the following code: leaq str(%rip), %rdi.
My full assembly code is the following:
.data
.text
.globl _main
_main:
pushq %rbp
movq %rsp, %rbp
subq $32, %rsp
leaq str(%rip), %rdi
callq _printf
And my Makefile:
build:
as main.s -o main.o
ld main.o -e _main -lc -macosx_version_min 10.13 -arch x86_64 -o main
run: build
./main
And finally the output of the command make build:
as main.s -o main.o
ld main.o -e _main -lc -macosx_version_min 10.13 -arch x86_64 -o main
Undefined symbols for architecture x86_64:
"str", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
make: *** [build] Error 1
How am I able to link the str command for use in macOS assembly?

How to run x86 .asm on macOS Sierra

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?)

Compile error OSX

I'm trying to compile a program called PEAR and it seems there is something wrong at this step.
I have Xcode installed.
Bernardos-MacBook-Pro:pear-0.9.0-src bernardo$ make
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C src all
gcc -c -Wall -fomit-frame-pointer -O3 -lm pear-pt.c -o pear-pt.o
clang: warning: -lm: 'linker' input unused
gcc -c -Wall -fomit-frame-pointer -O3 -lm reader.c -o reader.o
clang: warning: -lm: 'linker' input unused
reader.c:670:1: warning: unused function 'do_cpuid' [-Wunused-function]
do_cpuid(uint32_t selector, uint32_t *data)
^
1 warning generated.
gcc -Wall -fomit-frame-pointer -O3 -lm pear-pt.o args.o statistics.o reader.o -lm -lpthread -o pear
ld: warning: ignoring file args.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): args.o
ld: warning: ignoring file statistics.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): statistics.o
Undefined symbols for architecture x86_64:
"_decode_switches", referenced from:
_main in pear-pt.o
"_stat_test2", referenced from:
_assembly_FORWARD_LONGER in pear-pt.o
_assembly_READS_EQUAL in pear-pt.o
_assembly_REVERSE_LONGER in pear-pt.o
_assembly in pear-pt.o
"_usage", referenced from:
_main in pear-pt.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [pear] Error 1
make: *** [all] Error 2

Resources