An error occurred when trying to link the source code in Shosuisha's "Low Level Programming" on the mac terminal. I tried writing and setting the environment while looking at the Github page of this book, but I couldn't solve it anyway, so I would like to lend my wisdom.
Github for Low Level Programming: https://github.com/Apress/low-level-programmingError message
Applicable source code
% nasm -fmacho64 hello.asm&&ld hello.o&&./a.out Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol (s) not found for architecture x86_64
global start section .text start: mov rax, 0x02000004 mov rdi, 1 mov rsi, message mov rdx, 13 syscall mov rax, 0x02000001 xor rdi, rdi syscall section .data message: db "Hello, World", 10
I changed what was originally _start to start, or changed it to main or _main.Supplemental information (FW/tool version etc.)
mid-2012 13inch macbook air
intel core i5
macOS Catalina version 10.15.1
NASM version 2.14.02 compiled on Sep 28 2019
I saw it as
There are two places in start, have you both _main?
If both are _main
Another error message was
ld: dynamic main executables must link with libSystem.dylib for architecture x86_64
. Link and run
% nasm -fmacho64 hello.asm&&ld hello.o&&./a.out
. Thanks for your advice.asm-san
>Linking: ld -macosx_version_min 10.7.0 -lSystem -o hello_world
Did you try this option?
If i try to link with that option
ld: warning: -arch not specified ld: warning: ignoring file /usr/lib/libSystem.dylib, missing required architecture unknown in file /usr/lib/libSystem.dylib (2 slices) Undefined symbols for architecture unknown: "start", referenced from: implicit entry/start for main executable ld: symbol (s) not found for architecture unknown
The message has changed. By the way, the two parts that were the contents of
startwere changed to
_mainin response to otn's indication. Thanks for your advice.
Answer # 1
I think the github article about command line option specification was old at the time of writing (two years ago), and the target macOS version was also old. I tried it with macOS Mojave, but it was assembled by replacing the "start" with "_main" in the two places that were pointed out in the comments, and removing the "-macosx_version_min" option of the
ldcommand I was able to link with. Questioner's macOS is Catalina, but for reference.
bash-3.2 $cat hello2.asm global _main section .text _main: mov rax, 0x02000004 mov rdi, 1 mov rsi, message mov rdx, 13 syscall mov rax, 0x02000001 xor rdi, rdi syscall section .data message: db "Hello, World", 10 bash-3.2 $nasm -fmacho64 hello2.asm bash-3.2 $ld hello2.o -lSystem -o hello2 bash-3.2 $./hello2 Hello, World bash-3.2 $
Answer # 2
Are you aware of the cause (s) of Undefined symbols for architecture x86_64 :?
- macos (osx) - i get an error when i open the terminal
- macos (osx) - error with --time-style option of zsh ls command
- macos (osx) - when i drag and drop wxpython, the error "type error: ~ a'bool' is expected not'none type'" appears
- macos (osx) - i want to fix bash_profile error (syntax error) in terminal
- macos (osx) - docker error
- macos (osx) - error in rsync command in shell script
- macos (osx) - about fatal error displayed by git operation in terminal
- macos (osx) - sort_valus method error macos
- macos (osx) - i can't get up all the time with the error "visual studio code quit for an unexpected reason"
- macos (osx) - error in homebrew update
- macos (osx) - jupyter lab chromedriver error
- macos (osx) - cobol and mac terminal error messages
- c language compilation error using sdl2
- macos (osx) - i want to be able to access the in-house file server from the employee's home please tell me a vpn router that can
- macos (osx) - i want to move rails easily
- macos (osx) - combine wav files with sox
- macos (osx) - centralized management of files downloaded from github etc with homebrew (*for the purpose of reproducing the pc e
- macos (osx) - is it possible to set to print automatically after taking a screenshot?
- macos (osx) - password required for remote login with ssh command
- macos (osx) - about programming learning on youtube
- php - please tell me the continuous input of half-width alphanumeric characters by pressing and holding the mac keyboard
- macos (osx) - i can't push to a remote repository on github
- python - $pip install -r requirementstxt cannot be executed with an error
- python - i want to use the program in the folder obtained from github in the terminal
- macos (osx) - i can't push on github
- macos (osx) - what to do if your current account on github doesn't have permissions
- java - i want to import a project from github with eclipse
- macos (osx) - can't git clone from github