我的命令行程序的构建过程生成一个二进制文件(超过 500KB),当前必须通过 argv 的路径引用该文件。我想将此文件嵌入到可执行文件中。
在 Linux 上,它看来有可能 http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967 to use objcopy
从二进制文件创建目标文件:
objcopy --input binary --output elf32-i386 --binary-architecture i386 myfile.dat myfile.o
但是,OS X 开发人员工具链不包含 objcopy 命令。如果不安装 binutils,还有哪些可能性?
我从 Xcode 构建我的项目,并使用自定义构建规则生成该文件。
在链接阶段,传递参数-sectcreate <segname> <sectname> <file>
到链接器。如果您通过调用编译器来驱动链接器(这很常见),您可以将其传递为-Wl,-sectcreate,<segname>,<sectname>,<file>
.
您可以编写段和节的名称。
你会使用getsectdata()功能 https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/MachOReference/#//apple_ref/c/func/getsectdata随着_dyld_get_image_vmaddr_slide() https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/MachOReference/#//apple_ref/c/func/_dyld_get_image_vmaddr_slide在运行时获取指向数据的指针。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)