任何依赖于 C++/CLI 的 CPU 依赖于原生 C dll(任何用于 c++/cli 的 CPU) [英] Any CPU dependent on C++/CLI dependent on native C dll (any cpu for c++/cli)

查看:41
本文介绍了任何依赖于 C++/CLI 的 CPU 依赖于原生 C dll(任何用于 c++/cli 的 CPU)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题.我正在用 C# 包装一个 C dll.为此,我首先编写了一个 C++/CLI 包装器.本机 C 库链接到 C++/CLI 包装器.(C++/cli 项目中的链接器属性).

Here's my problem. I am wrapping a C dll in C#. To do this, I am first writing a C++/CLI wrapper. The native C library is linked to the C++/CLI wrapper. (Linker properties in C++/cli project).

现在的组织方式如下:- 原生 C .lib:x86 和 64 位.

Here's how it is all organised now: - The native C .lib: both x86 and 64bit.

  • 1 个包含 2 个项目的解决方案:
    • 链接到本机 C .lib 的 C++/CLI 包装器项目
    • C# 项目引用 C++/CLI 项目

    我的问题来自于我需要 C# 来定位任何 CPU"这一事实.但是这个选项在 C++/CLI 中不可用,因为它直接编译为本机代码.

    My problem comes from the fact that I need C# to target "Any CPU". But this option is not available in C++/CLI since it compiles directly to native code.

    我解决这个问题的想法是:- 在 x86 中编译 C++/CLI 包装器,然后更改配置并编译为 64 位.当它编译时,我想根据平台告诉它使用哪个dll.即:如果在 64 位编译,链接 64 位本地 C dll,否则如果 x86,链接 x86 本地 C.- 完成此操作后,我应该能够在我的 C# 平台中拥有任何 CPU 目标.在这里,我不会引用我的 C++/CLI 包装器项目,而是基于目标平台引用所需的 dll.

    My idea to solve this is: - Compile C++/CLI wrapper in x86 and then change the config and compile to 64 bit. When it compiles, I would like to tell it which dll to take based on the platform. ie: if compiling in 64bit, link 64 bit native C dll, else if x86, link x86 native C. - With this done, I should then be able to have Any CPU target in my C# platform. Here again, instead of referencing my C++/CLI wrapper project, I would reference the required dll based on the target platform.

    我的问题是:

    • 如何根据目标平台告诉 C++/CLI 项目链接到哪个 .lib?
    • 如何根据目标平台告诉 C# 项目要引用哪个 C++/CLI dll?

    让我补充一点,C# 项目是一个类库,供 x86 或 x64 客户端使用.

    Let me add that the C# project a CLASS LIBRARY to be used by an x86 or x64 client.

    我希望我的问题足够清楚.任何帮助将不胜感激!

    I hope my question is clear enough. Any helps would be appreciated !

    更新基于:.NET 项目中的条件引用,可以摆脱警告吗?...

    所以现在我已经使用条件编辑了我的 .csproj 文件来引用 dll,如下所示:

    So now I've edited my .csproj file using a condition to reference the dll as follows:

    <ItemGroup>
        <Reference Include="AlibCppWrapper, Version=1.0.4303.21410, Culture=neutral, PublicKeyToken=c0c17a53adc44091, processorArchitecture=AMD64"
                   Condition="$(Platform) == 'x64'">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>..x64DebugAlibCppWrapper.dll</HintPath>
        </Reference>
        <Reference Include="AlibCppWrapper, Version=1.0.4303.21410, Culture=neutral, PublicKeyToken=c0c17a53adc44091, processorArchitecture=x86"
                   Condition="$(Platform) == 'x86'">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>..DebugAlibCppWrapper.dll</HintPath>
        </Reference>
      </ItemGroup>
    

    不幸的是,这不起作用,因为 $(Platform) 设置为 AnyCPU...

    Unfortunately this doesn't work as the $(Platform) is set to AnyCPU...

    推荐答案

    您所描述的称为并行组装";(同一个程序集的两个版本,一个是 32 位,另一个是 64 位)...我想你会发现这些很有帮助:

    What you describe is known as "side-by-side assembly" (two versions of the same assembly, one 32 and the other 64 bit)... I think you will find these helpful:

    编辑 - 根据评论:

    您可以在此处找到适合您场景的演练:.NET DLL 包装 C++/CLI DLL 引用本机 DLL

    Here you can find a walkthrough for exactly your scenario: .NET DLL wrapping C++/CLI DLL referencing a native DLL

    这篇关于任何依赖于 C++/CLI 的 CPU 依赖于原生 C dll(任何用于 c++/cli 的 CPU)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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