gpt4 book ai didi

c# - [DllImport()] 可以处理静态 C 库吗

转载 作者:太空宇宙 更新时间:2023-11-03 23:47:54 24 4
gpt4 key购买 nike

我可以导入带有 .lib 扩展名的静态 C 库吗?

我有头文件:extern "C"__declspec(dllexport)

我可以使用 P/Invoke 助手从 header 源代码生成必要的代码,但问题仍然存在,

[DllImport()] 可以处理编译后的 C/C++ lib 文件吗?

最佳答案

DllImport 通过引用模块 (.DLL) 导出表中定义的条目来工作。 .LIB 文件不是模块,也没有按照 .DLL 的导出表。

来自 MSDN:

The DllImportAttribute attribute provides the information needed to call a function exported from an unmanaged DLL. As a minimum requirement, you must supply the name of the DLL containing the entry point. - Tell me more

您的问题:

Can [DllImport()] handle static c libraries?

没有。

但您始终可以将 .LIB 链接到 .DLL(假设您了解 c/c++)并 p 调用生成的 DLL,但这是一种间接解决方案,并不意味着 "is" 你的问题。

关于c# - [DllImport()] 可以处理静态 C 库吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27016163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com