My command-line program's build process generates a binary file (over 500KB) that currently has to be referenced by path from argv. I would like to embed this file in the executable instead.
On Linux, it appears possible to use objcopy
to make an object file from a binary file:
objcopy --input binary --output elf32-i386 --binary-architecture i386 myfile.dat myfile.o
However, the OS X developer toolchain doesn't include an objcopy command. Short of installing binutils, what are the possibilities?
I build my project from Xcode and the file is generated with a custom build rule.
During the link phase, pass the arguments -sectcreate <segname> <sectname> <file>
to the linker. If you're driving the linker via an invocation of the compiler, which is pretty common, you'd pass it as -Wl,-sectcreate,<segname>,<sectname>,<file>
.
You'd make up segment and section names.
You would use the getsectdata()
function along with _dyld_get_image_vmaddr_slide()
to get a pointer to the data at runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With