c++ - 如何在 Vala 中使用 C++ 库

标签 c++ extern vala vapi

我想使用vega用于处理 dicom 文件的库。其网站的示例代码如下:

#include <string>

#include "vega/dictionary/dictionary.h"
#include "vega/dicom/file.h"

int main() {
  // Set the dictionary file
  vega::dictionary::Dictionary::set_dictionary("/path/to/dictionary/dictionary.txt");
  
  // Read the DICOM file in
  const std::string file_name = "/path/to/dicom/file/dicom.dcm";
  vega::dicom::File file(file_name);
  
  // Print a human-friendly representation of the file to std::cout
  vega::Formatter formatter(std::cout);
  file.data_set()->log(formatter);
}

This page解释了包括 C 代码,但是 C++ 代码呢?

This official page指出“如果库是用 C++ 编写的,则无法将其绑定(bind)到 Vala,除非 C++ 库有单独的 C 绑定(bind)(例如 LLVM)。”。因此,在我看来,我不能使用 vega 库。我说得对吗?

编辑: 另外,将valabind/valabind-ccswig有帮助吗?

最佳答案

是的,我相信这是正确的。您只能链接 C 库,没有命名空间之类的东西。

要在 Vala 中使用您的 C++ 库,我想说您必须要么 a) 用 C 重写所有内容,但这显然需要大量工作,所以非常不可取,或者 b) 找到一个编写的库版本简单的 C 语言。

至于创建包装器,您必须从 C++ 公开 C api。 This问题的答案可以对此有所帮助。请注意,这可能包括编辑库的源代码,根据库的许可证,该源代码可能不可用或受到限制。

我不相信,就像 @wohlstad 一样,如果没有 C api,您就无法在 Vala 中使用纯 C++ 库。

关于c++ - 如何在 Vala 中使用 C++ 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73884235/

相关文章:

linux - "jiffies"的定义在哪里? "jiffies.h"仅在它外部

c++ - 翻译单元如何访问另一个翻译单元的全局范围?

gtk3 - 将 atspi-2 添加到 PKG_CONFIG_PATH

c - 将 Vala 与 C 结合使用时出现内存泄漏

vala - Vala 中的局部静态常量 : possible?

c++ - 如何将两个值从一个函数传递给同一类中的另一个函数?

c++ - Python中是否有类似于C++ STL map的结构?

c++ - Asio 点对点网络编程

c - 在 c 中使用 "extern"命令共享变量

C++ 未知名称类型