如何在托管C ++中链接C ++ lib文件 [英] How to link C++ lib file in managed C++

查看:101
本文介绍了如何在托管C ++中链接C ++ lib文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我有两个c ++ lib文件,我想在我的托管c ++应用程序中链接。喜欢它会给出56个链接错误,我能够弄清楚如何解决这些错误。以下是一些错误详情:



Quote:

错误LNK2005:private: static class std :: locale :: _ Locimp * __cdecl std :: locale :: _ Getgloballocale(void)(?_Getgloballocale @ locale @std @@ CAPAV_Locimp @ 12 @XZ)已经在msvcprtd.lib中定义(MSVCP110D.dll)



错误LNK2005:public:__ thishisall std :: exception :: exception(class std :: exception const&)(?? 0exception @ std @@ QAE @ ABV01 @@ Z)已在MSVCRTD.lib中定义(MSVCR110D.dll)



错误LNK2005:__calloc_dbg已在MSVCRTD.lib中定义(MSVCR110D.dll)



错误LNK2038:检测到'RuntimeLibrary'不匹配:值'MTd_StaticDebug'与ManagedWrapper.obj中的值'MDd_DynamicDebug'不匹配





如果有人知道如何解决这个问题,请告诉我。



我尝试了什么:



我从Proper中忽略了LIBCMTD.lib和MSVCRTD.lib tie-> Linker->在CLR项目中输入但仍然给出链接错误。



我将运行时库更改为多线程调试(/ MTd)属性 - > c / C ++ - > CLR项目的Code_Generation但我收到错误'/ clr'和'/ MTd'命令行选项不兼容

解决方案

< blockquote>请看我对这个问题的评论。



C ++在这方面是独特的语言。您可以使用常规的P / Invoke .NET API,但使用混合模式项目非常有用,您可以自由地混合托管+非托管。请参阅:

从托管代码调用本机功能 [ ^ ],

使用C ++ Interop(隐式PInvoke) [ ^ ],

在C ++中使用显式PInvoke(DllImport属性) [ ^ ],

原创和.NET互操作性 [ ^ ]。



-SA


Hello,
I have two c++ lib file which I want to link in my Managed c++ application. While liking it gives 56 link error and I am able to figure out how to resolve these errors. Here are few error details:

Quote:

error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Getgloballocale(void)" (?_Getgloballocale@locale@std@@CAPAV_Locimp@12@XZ) already defined in msvcprtd.lib(MSVCP110D.dll)

error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in MSVCRTD.lib(MSVCR110D.dll)

error LNK2005: __calloc_dbg already defined in MSVCRTD.lib(MSVCR110D.dll)

error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in ManagedWrapper.obj



Please let me know if anybody know how to solve this problem.

What I have tried:

I ignored LIBCMTD.lib and MSVCRTD.lib from Properties->Linker->Input in CLR project but still giving link error.

I changed runtime library to "Multi-threaded Debug (/MTd)" in Properties->c/C++->Code_Generation for CLR project but I get error "'/clr' and '/MTd' command-line options are incompatible"

解决方案

Please see my comment to the question.

C++ is unique language in this respect. You can use regular P/Invoke .NET API, but it's really beneficial to use mixed-mode projects where you can freely mix managed + unmanaged. Please see:
Calling Native Functions from Managed Code[^],
Using C++ Interop (Implicit PInvoke)[^],
Using Explicit PInvoke in C++ (DllImport Attribute)[^],
Native and .NET Interoperability[^].

—SA


这篇关于如何在托管C ++中链接C ++ lib文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆