How do I embed the contents of a binary file in an executable on Mac OS X?

后端 未结 2 492
失恋的感觉
失恋的感觉 2021-02-09 07:18

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 execu

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-09 07:33

    During the link phase, pass the arguments -sectcreate 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,,,.

    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.

提交回复
热议问题