从 D 调用 C++ 静态库

Calling C++ Static Library from D

我正在尝试从 D 模块调用 C++ 函数。我已按照此页面上的指南进行操作 http://dlang.org/spec/cpp_interface.html,但我无法使其正常工作。

我在visual studio2015年创建了一个解决方案,里面有两个项目,一个是D项目,一个是C++项目。我构建 C++ 项目并生成一个 .lib 文件。然后在 D 项目中,我在 Configuration Properties -> Linker -> General -> Library Files 中设置了 lib 文件的路径,但是当我 运行 解决方案时,我得到 Error43: Not a Valid Library File.

提前致谢

问题是您的库包含 COFF object files, but DMD expects them to be in the OMF format. (Take a look at "Can I link in C object files created with another compiler?" @ https://dlang.org/faq.html)

您需要做的是将库转换为 OMF 以便与 DMD 一起使用,例如 coff2omf tool. This tool is part of the DigitalMars extension package (check the freecompiler download 部分)或者,如果可以的话,使用一些 C++ 编译器,例如 DigitalMars C/C ++编译器,生成OMF库。

另外,看看:Converting COFF lib file to OMF format