在 mingw 中使用 msvc lib
我有一个带有开发工具的硬件(X射线传感器)。但afaiu这些是在msvc中内置的。所以我有一个 .lib 文件和 .dll 文件。如果我将此 lib 文件包含到我的项目中(我正在使用 qt),并将 dll 文件放入 exe 文件夹并使用 MSVC-Release 选项进行编译,则一切正常。但是当我尝试使用 mingw-Release 选项进行编译时。它失败了。
对“imp__ZN6IDcDrv6CreateEPKci”的未定义引用
对“imp__ZN6IDcDrv14GetDeviceCountEv”的未定义引用
您能否指出一些方法,以便我可以使用这些库。和使用 mingw 编译器
ps 的 dll 文件: 我尝试过但失败了 impdef dclibsn.dll>dclib.def
dlltool -dllname dclibsn.dll --def dclib.def --output-lib libdclibsn.a
这就是我的 def 文件的样子,
LIBRARY "dclibsn.dll"
EXPORTS
??0DcDrv@@QAE@ABV0@@Z
??0DcDrv@@QAE@V?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z
??0IDcDrv@@QAE@ABV0@@Z
??0IDcDrv@@QAE@XZ
??1DcDrv@@QAE@XZ
??4DcDrv@@QAEAAV0@ABV0@@Z
??4IDcDrv@@QAEAAV0@ABV0@@Z
?CaptureImage@DcDrv@@AAE_NHHHK_NHH@Z
?CloseUsbDevice@DcDrv@@AAE_NXZ
?ColumnDefectComp@DcDrv@@AAEGPBGH@Z
?CompensationImage@DcDrv@@AAEXPAGQAEHH@Z
?Create@IDcDrv@@SAPAVDcDrv@@PBDH@Z
请注意此文件中的最后一个条目(创建。)尝试在程序中调用它,
(.text+0x1ad): undefined reference to `_imp___ZN6IDcDrv6CreateEPKci'
如果我将行 ?Create@IDcDrv@@SAPAVDcDrv@@PBDH@Z 替换
为imp__ZN6IDcDrv6CreateEPKci 它编译,但给出错误。
The procedure entry point _ZN6IDcDrv6CreateEPKci could not be located in the dynamic link library dclibsn.DLL.
i have a hardware (xray sensor) which has development tools. but afaiu these are built in msvc. so i have a .lib file and .dll file . if i include this lib file to my project (i am using qt), and put dll file to the exe folder and compile using MSVC-Release option everytihng works. But when i try to compile using mingw-Release option. it fails.
undefined reference to `imp__ZN6IDcDrv6CreateEPKci'
undefined reference to `imp__ZN6IDcDrv14GetDeviceCountEv'
can you point some way out so that i can use these lib. and dll files using mingw compiler
ps:
i tried and failed
impdef dclibsn.dll>dclib.def
dlltool -dllname dclibsn.dll --def dclib.def --output-lib libdclibsn.a
and this is how my def file looks like
LIBRARY "dclibsn.dll"
EXPORTS
??0DcDrv@@QAE@ABV0@@Z
??0DcDrv@@QAE@V?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z
??0IDcDrv@@QAE@ABV0@@Z
??0IDcDrv@@QAE@XZ
??1DcDrv@@QAE@XZ
??4DcDrv@@QAEAAV0@ABV0@@Z
??4IDcDrv@@QAEAAV0@ABV0@@Z
?CaptureImage@DcDrv@@AAE_NHHHK_NHH@Z
?CloseUsbDevice@DcDrv@@AAE_NXZ
?ColumnDefectComp@DcDrv@@AAEGPBGH@Z
?CompensationImage@DcDrv@@AAEXPAGQAEHH@Z
?Create@IDcDrv@@SAPAVDcDrv@@PBDH@Z
note the last entry in this file (Create. ) i am trying to call this in the program and i get
(.text+0x1ad): undefined reference to `_imp___ZN6IDcDrv6CreateEPKci'
and if i replace the line ?Create@IDcDrv@@SAPAVDcDrv@@PBDH@Z
with imp__ZN6IDcDrv6CreateEPKci it compiles, but gives error.
The procedure entry point _ZN6IDcDrv6CreateEPKci could not be located in the dynamic link library dclibsn.DLL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看看这个:
如何在 MSVC 中使用 MingW 编译的库?
我的意思是用 extern“C”块包围#include。
因为使用 extern "C" 将指示编译器这些函数正在使用 C 链接,而不是 C++,这将阻止它对函数执行名称修改。
我认为名称修改会导致链接问题。
不知道这是否有助于自动使用 dll。希望它会。
因为我需要在MSVC 2005中编写一个基于CUDA的dll并在mingw中使用它。
希望这有帮助。 :-?
See this :
How to use libraries compiled with MingW in MSVC?
I mean surrounding #include with extern "C" block.
Because using extern "C" will instruct the compiler that the functions are using C linkage, not C++, which will stop it from performing name mangling on the functions.
I think name mangling causes problem in linkage.
Don't know this will help automatic using of dll or not. Hope it will.
Becuase i need to write a CUDA based dll in MSVC 2005 and use it in mingw.
Hope this help. :-?
我当然不是这个问题的专家,但我一直认为用 mingw 构建的项目无法使用 msvc 项目中的任何 dll 或库,因为它们是用不同的编译器构建的。
I am certainly no expert on the issue, but I always thought that a project built with mingw was not able to use any dll or libs from a msvc project, since they are built with different compilers.
这里有一个简单的问题:名称修饰方案,即从具有可能重载名称的 C++ 函数到仅通过名称识别函数的字符串的映射,对于 MS 编译器和 GCC 来说是不同的。因此,函数名称不同,MingW 搜索自己的损坏名称格式 (
_ZN6IDcDrv6CreateEPKci
),但找不到 microsoftly 损坏名称 (?创建@IDcDrv@@SAPAVDcDrv@@PBDH@Z
)。现在,如果这两个库真正使用 C++ 功能,那就更好了。假设您将一个 C++ 字符串从库传递到您的程序并返回 - 绝对不能保证该字符串的 MS 实现与 GNU 实现是二进制兼容的,因此您可能最终会遇到严重的错误。
但是,如果这些函数的接口是 C 兼容的(可以用 POD 术语表示),您可以在
extern "C"
块中声明这些函数,从而禁用名称修改。看来您正在构建的库的开发人员没有这样做。如果这是不必要的(抱歉,我无法将 MSVC 名称分解为函数签名,所以真的无法分辨),您应该针对库提交一个错误,并让它们使用外部“C”
。如果这是不可能的,请在 MSVC 中编写一个包装器,调用它们的函数并在extern "C"
中声明其自己的函数。You have a simple problem here: The name mangling scheme, i.e. the mapping from C++ functions with possibly overloaded names to strings that identify functions by name only, for the MS compiler and for GCC is different. So, the function names are different, and the MingW searches for its own mangled name format (
_ZN6IDcDrv6CreateEPKci
) and can't find the microsoftly mangled name (?Create@IDcDrv@@SAPAVDcDrv@@PBDH@Z
).Now, if these two libraries are truly using C++ features, this is all the better. Suppose you'd pass a C++ string from the library into your program and back - there is absolutely no guarantee that the MS implementation of the string is binary-compatible to the GNU implementation, so you'd probably end up with nasty errors.
However, if the interface of these functions is C-compatible (can be expressed in POD terms), you can declare the functions within an
extern "C"
block and thus disable name mangling. It seems the developers of the lib you are building against didn't do this. If this was unnecessary (sorry, I can't demangle MSVC names to a function signature, so really can't tell), you should file a bug against the library and have them declare the interface or as large parts as possible withextern "C"
. If that is impossible, write a wrapper in MSVC that calls their functions and declares its own functions within anextern "C"
.正如@thithon 所指出的,您的问题是 C 名称损坏。正如他建议的那样,您应该执行外部“C”操作来避免这种情况。
入口点错误是因为您的 dll 中可能没有 main()。只需添加一个(即使它是空的,也没关系),该错误就会消失。
As noted by @thithon, your problem is C name mangling. As he suggests, you should do the extern "C" thing to avoid that.
The entry point error is because you probably dont have a main() in your dll. Just add one (even if its empty, it doesnt matter), and that error will go away.