简体   繁体   English

是否可以在 html5 中使用 C++ 代码?

[英]Is it possible to use C++ code in html5?

I want to make an app for which i need to include a part of my c++ code for calculation.我想制作一个应用程序,我需要在其中包含我的 C++ 代码的一部分进行计算。 For GUI i'm using HTML5.对于 GUI,我使用的是 HTML5。 So is it possible to include C++ code into HTML5 ?那么是否可以将 C++ 代码包含到 HTML5 中?

No. You can't do that.不,你不能那样做。 Try porting your C++ to JavaScript.尝试将您的 C++ 移植到 JavaScript。 You could take a look at this project that claims it can convert C++ code to JavaScript.你可以看看这个声称它可以将 C++ 代码转换为 JavaScript 的项目。 I have never tried this myself.我自己从来没有尝试过这个。

Otherwise, you could write a CGI to use your C++ program and use AJAX to "remote execute it".否则,您可以编写一个 CGI 来使用您的 C++ 程序并使用 AJAX 来“远程执行它”。

It is not easily possible to use C++ code in HTML5;在 HTML5 中使用 C++ 代码并不容易; but it depends what you really want to do.但这取决于您真正想要做什么。

You should first understand what HTTP and HTML5 really are, and where you want the C++ code to run (in the browser - on the HTTP client side, or in the server - on the HTTP server side).您应该首先了解什么是HTTPHTML5 ,以及您希望 C++ 代码运行的位置(在浏览器中 - 在 HTTP 客户端,或在服务器中 - 在 HTTP 服务器端)。

If you want to use C++ code on the client side (in the browser), you probably want something like Google Native Client .如果您想在客户端(在浏览器中)使用 C++ 代码,您可能需要类似Google Native Client 的东西。 Not all browsers are supporting it, and your user needs to enable it.并非所有浏览器都支持它,您的用户需要启用它。 You could also consider compiling your C++ code to Javascript with Emscripten .您还可以考虑使用Emscripten将 C++ 代码编译为 Javascript。

If you want C++ code on the server side, you may want to use CGI or FastCGI techniques, or make your C++ code a specialized HTTP server by using some HTTP server library (like libonion or Wt )如果您希望在服务器端使用 C++ 代码,您可能需要使用CGIFastCGI技术,或者通过使用某些 HTTP 服务器库(如libonionWt )使您的 C++ 代码成为专门的 HTTP 服务器

See also this question .另请参阅此问题

尝试使用 Javascript 进行计算。

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

相关问题 是否可以在ARC中使用Native C ++代码? - Is it possible to use Native C++ code in ARC? 是否有可能触发由Minko中的html事件启动的c ++代码? - is it possible to trigger c++ code, initiated by html events in minko? 用于HTML5音频的C ++流服务器 - C++ stream server for HTML5 Audio 是否可以使用本机C ++代码在iOS设备上写入文件 - Is it possible to use native C++ code to write a file on an iOS device 是否可以禁止在一小段C ++代码中使用某些寄存器? - Is it possible to prohibit the use of certain registers for a small snippet of C++ code? 是否可以在WatchOS / WatchKit应用程序中使用C ++代码 - Is it possible to use C++ code in WatchOS / WatchKit app 是否可以使用C ++模板来控制代码生成? - Is it possible to use C++ template to control code generation? 在C ++中是否可以在有和没有编译时常量的情况下使用相同的代码? - Is it possible in C++ to use the same code with and without compile time constants? 是否可以更改此代码以避免使用C ++ lambda表达式? - Is it possible to change this code in order to avoid the use of the C++ lambda expression? 是否可以在C ++代码中使用Linux Perf profiler? - Is it possible to use Linux Perf profiler inside C++ code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM