How to make clang lld output a binary file?


This Content is from Stack Overflow. Question asked by cyao

I’m doing a bit of osdev on my mobile (my PC broke XD) and I’m using termux

In this app there isn’t the binutils and gcc i686/x86_64 toolchanins, so the only c compiler that can output i686 stuff is clang & lld

I already managed to make compile everything into a elf file with clang -target i386-linux-elf -nostdlib -Wl,link.ld -fuse-ld=lld -o kernel/kernel.elf $^

But nows my problem: I couldn’t get clang and lld to output binary files (the OUTPUT_FORMAT(binary) in the linker script gives errors) and if I use objcopy/stript it doesn’t recognize the elf format (since they are for the android elf)

So how can I produce a binary file from the elf file?


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?