在运行时添加新代码

在运行时添加新代码

本文介绍了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, thencompile it to a dll (invoking the compiler with system), andthen load the dll. The first is simple, the last isn't toodifficult (but will require implementation specific code), butthe middle step can be challenging: obviously, it only works ifthe compiler is installed on the system, but you have to findwhere it is installed, verify that it is the same version (orat least a version which generates binary compatible code),invoke it with the same options that were used when your codewas compiled, and process any errors.

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

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

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

08-12 07:22