Steps to reproduce:
- Install a version of Visual Studio (I used VS Community 2022). Install OpenCASCADE 7.6.0.
- Create a C++ .NET CLR project using Visual Studio 2022 targeting .net6.0.
- Change settings to include OpenCASCADE header and library files.
- Edit the main header by replacing the code within it with below:
#pragma once
//for OCC graphic
#include <OpenGl_GraphicDriver.hxx>
//wrapper of pure C++ classes to ref classes
#include <NCollection_Haft.h>
namespace ClrClsLibDotNetCoreMwe {
public ref class Class1
{
// TODO: Add your methods for this class here.
};
}
- Attempt to build.
Issue: The build fails with the following complain:
1>C:OpenCASCADE-7.6.0-vc14-64opencascade-7.6.0incNCollection_DefaultHasher.hxx(34,1): error C2872: 'HashCode': ambiguous symbol
1>C:OpenCASCADE-7.6.0-vc14-64opencascade-7.6.0incNCollection_DefaultHasher.hxx(34,1): message : could be 'HashCode'
1>C:OpenCASCADE-7.6.0-vc14-64opencascade-7.6.0incNCollection_DefaultHasher.hxx(34,1): message : or 'System::HashCode'
What fixes the problem:
- Either Targeting .NET Framework instead of .NET Core (/clr instead of /clr:netcore).
- Or removing one of the headers.
Please see if there is a way where I can keep both the headers and target .NET Core?
I have looked around for a possible solution before posting this question here. A promising solution was to disable implicit usings. However, that didn’t pan out.
2
Answers
Actually, qualifying one of the namespaces with ::HashCode in the header file fixed the problem for me. I was having significant difficulties in preventing the auto use of the System namespace.
I had the same problem.
In my case, the "using namespace System;" included in the header file. The text caused the problem.
Thanks!