在 C++ 程序中嵌入数据 [英] Embed data in a C++ program

查看:28
本文介绍了在 C++ 程序中嵌入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 SQLite 的 C++ 程序.我想将 SQL 查询存储在一个单独的文件中——一个纯文本文件,不是源代码文件——而是将该文件像资源一样嵌入到可执行文件中.

I've got a C++ program that uses SQLite. I want to store the SQL queries in a separate file -- a plain-text file, not a source code file -- but embed that file in the executable file like a resource.

(这必须在 Linux 上运行,因此据我所知,我无法将其存储为实际资源,但如果它用于 Windows,那将是完美的.)

(This has to run on Linux, so I can't store it as an actual resource as far as I know, though that would be perfect if it were for Windows.)

有什么简单的方法可以做到,或者它是否会有效地要求我为 Linux 编写自己的资源系统?(很容易,但需要更长的时间.)

Is there any simple way to do it, or will it effectively require me to write my own resource system for Linux? (Easily possible, but it would take a lot longer.)

推荐答案

您可以使用 objcopy 将文件内容绑定到您的程序可以使用的符号.例如,请参见此处更多信息.

You can use objcopy to bind the contents of the file to a symbol your program can use. See, for instance, here for more information.

这篇关于在 C++ 程序中嵌入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆