生成 C++运行时代码,编译并运行
是否有可以链接到任何软件的多平台 C++ 编译器?
假设我想在运行时生成 C++ 代码,编译并运行它。 我正在寻找一个紧凑的解决方案(一堆类),最好是 LGPL/BSD 许可证:)
据我所知,它可以在 Java 和 C# 中完成。那么c++呢?
is there a multiplatform c++ compiler that could be linked into any software ?
Lets say I want to generate c++ code at runtime, compile it and run it.
I'm looking for a compact solution (bunch of classes), preferably LGPL/BSD licence :)
As far as I know it can be done in Java and c#. What about c++ ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
好吧,也许 CLang 的模块之一会有所帮助? C++ 方面还没有干,但肯定很快就会干。
Well maybe one of the modules of CLang will be of help? It's not dry yet on the C++ side but certainly will be soon.
我不知道有任何针对 C++ 的开源脚本,但如果您想要小型且紧凑的脚本并且不沉迷于 C++ LUA 可能是您的一个选择
I don't know of any open source ones for C++, but if you want small and compact scripting and are not hung up on C++ LUA might be an option for you
我会完全放弃 C++ 并使用 Google V8。如果你想使用 C++,因为使用你的应用程序的人只知道这一点,那么他们使用 javascript 应该没有困难。
而且速度实在是太快了。 Javascript 也是一门很酷的语言。
I'd drop C++ altogether and use Google V8. If you wanted to use C++ because the people using your app only know this, they should have no difficulties going to javascript.
And it's damn fast. And Javascript is a cool language too.
几年前,我在 Linux 中完成了这一工作,将 C++ 代码生成到文件中,通过 shell 执行(使用 gcc)对其进行编译,然后动态链接到生成的库中。当然,平台之间的动态链接有所不同。
I've done this years ago in Linux by generating C++-code into a file, compile it by shell execute (with gcc) and then linking in the generated library dynamically. The dynamic linking differs of course between platforms.
这种事情在 C++ 中要困难得多,因为该语言不使用抽象机器细节的虚拟机(或“运行时”)。
您可以查看 gcc,它位于 GPL IIRC 之下,并且所有主要平台都存在端口。
This kind of thing is much much harder in C++, because the language doesn't use a virtual machine (or "runtime") that abstracts machine specifics away.
You could look into gcc, it's under the GPL IIRC, and ports exist for all major platforms.
当我们研究脚本时,我们选择了 AngelScript,因为它与 C++ 相似。
V8 很棒,但它肯定仅限于某些平台,AngelScript 更容易编译,并且可能更容易学习(如果您来自 C++),并且它有 zlib 许可证。
http://www.angelcode.com/angelscript/
When we looked into scripting we chose AngelScript because of the similarity with C++.
V8 is great but it's certainly limited to some platforms, AngelScript is a lot easier to compile with and probably to learn (if you came from C++) and it has a zlib license.
http://www.angelcode.com/angelscript/