dsgd4654674 2018-12-07 23:18 采纳率: 0%
浏览 35

我可以使用动态链接嵌入我的C / C ++项目吗?

Take python as example, a C/C++ program can load libpython.so dynamically and create a python VM, and then feed user scripts to the python VM.

Is their a way to use go like this? Namely, dynamically load it from the user's system environment.

We want to embed go to our project for scripting, but we don't want to package it to our final binary program.

Thanks.

  • 写回答

1条回答 默认 最新

  • dongwen6743 2018-12-07 23:55
    关注

    On some platforms like Linux you can build your Go code with -buildmode=c-shared to get a shared library which can then be linked into a program written in another language like C.

    Some examples and documentation are here: https://github.com/vladimirvivien/go-cshared-examples

    Note that this does not make Go a scripting language--you still need to build shared libraries from Go code. However, you could conceivably build them while your application is running and load them using dlopen() and dlsym(). This is the same as how you could compile C code by launching a C compiler from inside your application, then load it.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100