【问题标题】:CLR namespace does not existCLR 命名空间不存在
【发布时间】:2015-09-29 00:09:25
【问题描述】:

我有一个带有 2 个函数的 C# 项目

namespace LibiqCommonStructures 
{
  public class BlackLevelData : List<BlackLevelLookupTable>
  {
      public BlackLevelData()
      {
      }

       public BlackLevelData(BlackLevelData original)
          : base(original.DeepCopy())
      {
      }

       public void AddLookupTable(double gain, double exposure, double[] levels)
      {
          var table = new BlackLevelLookupTable
          {
              AnalogGain = gain,
              ExposureTime = exposure,
             ChannelLevels = levels
          };

          Add(table);
      }
  }
}

SaturationLevelData 相同

我创建了一个 c++\CLI 项目,我想将这两个类作为参数放入一个函数中

#pragma once
#include "Preprocessor.h"


using namespace LibiqCommonStructures;

namespace ToolBox {

    public ref class PreprocessorWrapper
    {
    public:        
        PreprocessorWrapper();        
        void Function1(BlackLevelData^ blackLevelData, SaturationLevelData^ saturationLevelData);
    private:
        Preprocessor* _preprocessor;
    };
}

标题

 #include "PreprocessorWrapper.h"


void ToolBox::PreprocessorWrapper::Function1(BlackLevelData^ blackLevelData, SaturationLevelData^ saturationLevelData)
{    
    _preprocessor->Function1();
}

ToolBox::PreprocessorWrapper::PreprocessorWrapper()
{
    _preprocessor = new Preprocessor();
}

这是我得到的错误

Error   2   error C2871: 'LibiqCommonStructures' : a namespace with this name does not exist    g:\iqtool2\src\libiqtool\preprocessor_interop\PreprocessorWrapper.h 5   1   Preprocessor_interop
Error   8   error C2448: 'ToolBox::PreprocessorWrapper::Function1' : function-style initializer appears to be a function definition G:\IQTool2\src\libiqtool\Preprocessor_interop\PreprocessorWrapper.cpp   5   1   Preprocessor_interop
Error   6   error C2065: 'SaturationLevelData' : undeclared identifier  G:\IQTool2\src\libiqtool\Preprocessor_interop\PreprocessorWrapper.cpp   4   1   Preprocessor_interop
Error   7   error C2065: 'saturationLevelData' : undeclared identifier  G:\IQTool2\src\libiqtool\Preprocessor_interop\PreprocessorWrapper.cpp   4   1   Preprocessor_interop
Error   4   error C2065: 'BlackLevelData' : undeclared identifier   G:\IQTool2\src\libiqtool\Preprocessor_interop\PreprocessorWrapper.cpp   4   1   Preprocessor_interop
Error   5   error C2065: 'blackLevelData' : undeclared identifier   G:\IQTool2\src\libiqtool\Preprocessor_interop\PreprocessorWrapper.cpp   4   1   Preprocessor_interop
Error   3   error C2061: syntax error : identifier 'BlackLevelData' g:\iqtool2\src\libiqtool\preprocessor_interop\PreprocessorWrapper.h 13  1   Preprocessor_interop

你能看出我在这里做错了什么吗?

是的,我已添加 C# 项目作为参考

【问题讨论】:

  • 在您的 C++/CLI 项目中,您是否添加了对包含 LibiqCommonStructures 的项目/程序集的引用?
  • 您是否添加了 C# dll 作为参考?
  • @DmytroShevchenko 是的,我做到了
  • 检查此答案是否对您有帮助:stackoverflow.com/questions/16732789/…
  • @DmytroShevchenko 不,我也做了这两个

标签: c# c++-cli


【解决方案1】:

首先,确保您正在使用 /clr 开关构建您的 C++ 项目。奇怪的是,您至少没有引用系统程序集。

其次,您提供的屏幕截图似乎表明您的 C++/CLI 项目正在使用 .NET Framework v4.0。假设您的 C# 项目使用 .NET Framework v4.5,请尝试更新您的 C++/CLI 项目以匹配。您可以手动编辑项目文件 (.vcxproj),如下所示:

<PropertyGroup Label="Globals">
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>

我通过使用 Visual Studio 2013 将版本更改为 v4.0 来重现您的问题。

【讨论】:

    猜你喜欢
    • 2013-02-09
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2014-10-19
    • 1970-01-01
    • 1970-01-01
    • 2014-02-15
    • 1970-01-01
    相关资源
    最近更新 更多