如何在 Vala 中使用 C++ 库

rns*_*nso 2 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);
}
Run Code Online (Sandbox Code Playgroud)

本页解释了包括 C 代码,但是 C++ 代码呢?

该官方页面指出“如果该库是用C++编写的,则无法将其绑定到Vala,除非有C++库的单独C绑定(例如,LLVM)。”。因此,在我看来,我不能使用 vega 库。我对么?

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

cs1*_*459 5

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

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

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

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