在运行时生成可执行文件 - C++ / Visual C++
也许你可以帮我解决一个与 C++ 语言相关的问题:
是否可能,或者是否有办法在 C++ Windows 应用程序的运行时生成可执行文件?
为了向您说明我为什么要问这个问题,我将详细介绍我现在正在考虑的场景:
我有一个 C++ Windows 应用程序,它更像是一个编辑器,用户在其中输入一些数据并进行一些配置,因此当一切都完成时完成后,用户单击“运行”按钮,该编辑器根据用户输入的数据和配置,创建一些 C++ 或 C# 代码文件,编译它们并生成一个可执行文件,用户可以简单地使用而无需输入任何行自己写的代码。
是否可以?请您告诉我如何进行搜索或在哪里可以找到帮助?
Maybe you can help me with a question I have, related to C++ language:
Is it possible or, is there a way to generate an executable file at runtime of a C++ Windows application?
To illustrate you why I'm asking this, I will detail the scenario that I'm thinking right now:
I have a C++ Windows Application that is more like an editor, where the user inputs some data and make some configurations, so when everything is done, the user clicks the "Run" button and this editor based on the user input data and configurations, creates some C++ or C# code files, compiles them and generates an executable file that the user can simply use without having to enter any line of code by himself.
Is it possible? Please can you give me a clue of how to do my search or where to find some help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然有可能,编译器本身很可能就是满足这个要求的程序。
如果您想在不调用编译器的情况下完成此操作(从而生成源代码来提供它),则需要了解有关平台的机器语言和可执行文件格式的大量信息。
Of course it is possible, the compiler itself is likely a program that fulfils this requirement.
If you want to do it without just invoking a compiler though (and thus generate source code to feed it), you need to learn quite a bit about the machine language and executable file format of your platform.
您可以简单地从应用程序调用外部编译器,让编译器构建您的可执行文件,如果编译成功,您可以运行生成的可执行文件。您甚至可以在应用程序中捕获编译器的输出。
You could simply make a call from your application to an external compiler, make the compiler build your executable and if the compilation is successful you could run the resulting executable. You can even capture the output of the compiler in your application.