简体   繁体   English

是否有可直接嵌入C / C ++程序的C / C ++编译器/链接器?

[英]Is there a C/C++ compiler/linker which is embedable directly in a C/C++ program?

The idea is to generate C/C++ code at run-time, compile it to a shared object, and load that shared object in the current process. 我们的想法是在运行时生成C / C ++代码,将其编译为共享对象,并在当前进程中加载​​该共享对象。

I know it could be done by using an existing compiler installation on the host platform (GCC or MSVC), but in a practical scenario the client don't necessary have such installation. 我知道可以通过在主机平台(GCC或MSVC)上使用现有的编译器安装来完成,但在实际情况下,客户端不需要进行此类安装。 So the idea is to statically link with such compiler and linker. 所以我的想法是静态链接这样的编译器和链接器。

For example in Java, you can compile .java classes directly from java code. 例如,在Java中,您可以直接从java代码编译.java类。 It can be used to generate automatically a Buisness Objects from a database schema. 它可用于从数据库模式自动生成Buisness对象。

You may be able to do this with the c-language front end ( clang ) to llvm . 你可以用c语言前端( clang )到llvm来做到这一点。 The static analyzer built on top of clang may give you some ideas on how to proceed. 构建在clang之上的静态分析器可以为您提供有关如何继续的一些想法。

There is tinyC: http://bellard.org/tcc/ . 有tinyC: http ://bellard.org/tcc/。 I know nothing similar for C++. 我对C ++一无所知。

Google 'c interpreter embed' and you'll get as a first hits 谷歌的'c诠释者嵌入',你将获得第一次点击

YMMV 因人而异

As far as I know, such thing can not be done for c or c++. 据我所知,c或c ++无法做到这样的事情。 You have to start a new process (in which you execute a compiler), and requires a compiler to be installed. 您必须启动一个新进程(在其中执行编译器),并且需要安装编译器。

你可能想看看破解语言 ,基于llvm,它处于早期阶段,但似乎与你试图实现的目标非常接近。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM