C ++在运行时添加新代码 [英] C++ add new code during runtime

查看:190
本文介绍了C ++在运行时添加新代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C ++(在xcode和code :: blocks),我不知道。
我想在运行时编译一些东西。

I am using C++ (in xcode and code::blocks), I don't know much. I want to make something compilable during runtime.

例如:

char prog []={"cout<<"helloworld " ;} 

它应该编译prog的内容
阅读有关quines,但它没有帮助我。

It should compile the contents of prog. I read a bit about quines , but it didn't help me .

推荐答案

这是可能的,但不可移植,
基本上,你必须将代码写入文件,然后
将其编译为dll(使用 system 调用编译器)和
然后加载dll。第一个是简单的,最后一个不是太多
困难(但将需要实现特定的代码),但
中间步骤可以是具有挑战性的:显然,它只有当
编译器安装在系统上,但是你必须找到
它安装,验证它是相同的版本(或
至少一个版本,生成二进制兼容代码),
使用与编译代码
时使用的相同选项调用它,并处理任何错误。

It's sort of possible, but not portably, and not simply. Basically, you have to write the code out to a file, then compile it to a dll (invoking the compiler with system), and then load the dll. The first is simple, the last isn't too difficult (but will require implementation specific code), but the middle step can be challenging: obviously, it only works if the compiler is installed on the system, but you have to find where it is installed, verify that it is the same version (or at least a version which generates binary compatible code), invoke it with the same options that were used when your code was compiled, and process any errors.

C ++不是专为此而设计。 (编译语言一般不是
。)

C++ wasn't designed for this. (Compiled languages generally aren't.)

这篇关于C ++在运行时添加新代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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