将普通的二进制文件绑定到可解除的
以下问题与实际问题无关,但我只是好奇:
如何将整个文件与可执行文件链接并在C / C ++中获取该块的起始地址和大小?有时,拥有一个可执行文件,其中包含一些归因性,这些归因于通常是在运行时读取的外部文件。
任何与任何编译器系统或平台相关的示例都将不胜感激。
除此之外 我故意不使用与特定语言有关的任何标签发布此问题,而只是与与特定实现相关的标签。
The following question isn't related to an actual problem but what I just was curious about:
How can I link a whole file with an executable and get the starting address and size of that block at runtime in C / C++ ? Sometimes it would be nice to have a single executable which contains some resorces which conventionally would be external files to be read at runtime.
Any examples related to any compiler system or platform would be appreciated.
Aside from that it would be nice to have standard means in C / C++ to do that.
I intentionally don't post this questions with any tag related to specific languages but just with tags that are related to specific implementations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于没有适当的答案,所以我写了一些C ++ 20程序,将文件转换为带有未签名的char数组和一个带有此数组的声明的标题文件的C文件。
第一个参数是要成为数组的文件,第二个参数是没有扩展名的输出文件的名称,第三个参数是数组的名称,并且有一个可选的第四参数,每行字节数,默认为16。
写作所有 to 直接流太慢,因此散装。
编译较大文件的输出可能真的很慢,但是输出的C-part通常并不是项目中其他文件的任何依赖性。
As there was no proper answer I wrote a little C++20-program that converts a file to a C-file with a unsigned char array and a header file with just the declaration of this array.
The first parameter is the file to become the array, the second parameter is the name of the output-files without an extension, the third parameter is the name of the array and there's an optional fourth parameter with the number of bytes per line, which is defaulted to 16.
Writing everything to directly a stream was too slow, therefore the bulk-string.
Compiling the output of a larger file can be really slow but the C-part of the output usually isn't any dependency of other files in the project.