我正在尝试将二进制文件编译为MACH_O对象文件,以便将其链接到dylib.dylib是用c/c ++编写的.
在linux上使用以下命令:ld -r -b binary -o foo.o foo.bin
我在OSX上尝试了各种选项,但无济于事:
ld -r foo.bin -o foo.o
gives:
ld: warning: -arch not specified
ld: warning: ignoring file foo.bin, file was built for unsupported file format which is not the architecture being linked (x86_64)
Run Code Online (Sandbox Code Playgroud)
创建一个空的.o文件
ld -arch x86_64 -r foo.bin -o foo.o
ld: warning: ignoring file foo.bin, file was built for unsupported file format which is not the architecture being linked (x86_64)
Run Code Online (Sandbox Code Playgroud)
再次创建空的.o文件.用nm检查文件给出:nm foo.o nm:没有名称列表
二进制文件实际上是将下载到外部设备的固件.
谢谢你的期待
我有一个嵌入式 C 项目,正在使用 eclipse 进行编译。我需要将二进制文件作为常量数组读入应用程序代码。
该二进制文件约为 200kB,需要成为应用程序代码的一部分,以便应用程序代码可以随时读取二进制映像并将其加载到板上需要此初始化映像的另一个设备中。
我通常会将图像加载到板上的非易失性存储器中,然后读取并移动它,但这在这里不可行,它必须是可执行图像的一部分。
我可以在 makefile 中通过将 .bin 文件链接到某个地址来完成此操作,或者在 C 代码中执行此操作,例如
const char binFileImage [] = { file.bin };
Run Code Online (Sandbox Code Playgroud)
这显然行不通,但我还没有想出可行的语法。
仅供参考,file.bin确实是一个二进制文件。
关于如何做到这一点有什么想法吗?