[英]How to compile a C++/CLI program into .lib and link it with a pure unmanaged C++ program?
I'm following this http://www.codeproject.com/Articles/10020/Using-managed-code-in-an-unmanaged-application 我正在关注这个http://www.codeproject.com/Articles/10020/Using-managed-code-in-an-unmanaged-application
The example consist of 3 binaries: 该示例包含3个二进制文件:
The C++ code calls on the C++/CLI code, which then calls on the C# code, to achieve a way of running C# codes from C++. C ++代码调用C ++ / CLI代码,然后调用C#代码,以实现从C ++运行C#代码的方式。
The problem is, the C++/CLI is compiled as a .dll, when I tried to compile it into .lib, so that the C++ code and be linked together with the C++/CLI code, it fails. 问题是,当我尝试将C ++ / CLI编译为.dll时,它会将C ++代码与C ++ / CLI代码链接在一起,因此它失败了。
So that the end result will only consist of 2 binaries. 这样最终结果将仅包含2个二进制文件。
The error 错误
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl IMessageBoxWrapper::Destroy(class IMessageBoxWrapper *)" (__imp_?Destroy@IMessageBoxWrapper@@SAXPAV1@@Z) referenced in function _main C:\Users\Zero\Desktop\UmanagedApp\UmanagedApp\main.obj UmanagedApp
Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class IMessageBoxWrapper * __cdecl IMessageBoxWrapper::CreateInstance(void)" (__imp_?CreateInstance@IMessageBoxWrapper@@SAPAV1@XZ) referenced in function _main C:\Users\Zero\Desktop\UmanagedApp\UmanagedApp\main.obj UmanagedApp
Since you no longer have a DLL, you shouldn't be using __declspec(dllimport)
at all. 由于您不再拥有DLL,因此根本不应该使用
__declspec(dllimport)
。
Actually, I strongly discourage using that on classes in any case, it's very fragile. 实际上,无论如何我都强烈建议不要在类上使用它,因为它非常脆弱。
So just remove DLLAPI
from all the class definitions. 因此,只需从所有类定义中删除
DLLAPI
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.