是否可以在 javascript 应用程序中使用 c++ 库

Is it possible to use a c++ library in a javascript application

我正在尝试构建一个 javascript 应用程序,我需要使用 c++ 库。有什么方法可以在 javascript 应用程序中包含 C++ 库吗?

是的。您可以利用 emscripten 将 C++ 转换为 JavaScript。您也可以

  • 使用 Native Messaging 与 shell 脚本通信

  • 使用本地服务器向 shell 脚本发送 POST 命令,该脚本运行本机 shell 脚本,例如,参见 shell_exec() 调用PHP 在 How to programmatically send a unix socket command to a system server autospawned by browser or convert JavaScript to C++ souce code for Chromium?

如果您正在使用 Node.js 并且您的库是作为 DLL 提供的,您可以使用 node-ffi (Foreign Function Intergface). For other options check this post.