如何在浏览器中将C ++编译为JavaScript? [英] How do I compile C++ to JavaScript in a browser?

查看:84
本文介绍了如何在浏览器中将C ++编译为JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 Emscripten

I'm aware of Emscripten and LLVM, but neither are written in JavaScript intended for a browser.

据我所知,这些工具确实存在,但尚未组合在一起,但是我很可能会缺少一些关键因素,这使得很难在浏览器中将C ++编译为JavaScript.

As far as I can tell, the tools exist, but they haven't been put together, but I could very well be missing some key factor that makes it very difficult to compile C++ to JavaScript in a browser.

因此,我将提到我的幼稚实现:

So I'll mention my naive implementation:

  1. 将Emscripten编译为C,然后使用Clang将其编译为LLVM,然后使用Emscripten将其编译为JavaScript.
  2. 将Clang编译为LLVM,然后通过Emscripten将其编译为JavaScript.
  3. 编写一些C ++并通过JavaScript Clang运行它,然后通过Emscripten运行该LLVM以获得JavaSscript
  4. 运行生成的JavaScript!

我确定我的脚步中遗漏了一些东西.请让我知道,也请让我知道社区是否有任何努力来解决那些遗漏的部分.

I'm sure I'm missing something from my steps. Please let me know, and let me know if there are any efforts by the community to resolve those missing pieces.

JSCPP 是我找到的最接近的,但是它缺少许多功能,并且坦率地说,作者试图自己改写解析器等,而不是使用现有的工具,这是荒唐的.尽管如此,还是很整齐.

JSCPP is the closest I've found, but it lacks a lot of features and frankly the author took on an absurd undertaking, by trying to rewrite the parser etc. on his own, rather than using existing tools. Still, close and pretty neat.

推荐答案

从理论上讲,有可能开发出 Emscripten的自托管版本在浏览器中运行,尽管尚未完成.

In theory, it may be possible to develop a self-hosting version of Emscripten that runs in a browser, though this hasn't been done yet.

或者,可以使用 x86模拟器在其中运行C ++编译器(甚至是整个操作系统)JavaScript .

这篇关于如何在浏览器中将C ++编译为JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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