miercuri, 16 martie 2011

Error C2872 ambiguous symbol

I was trying to compile one of my C++ projects and ran into this error:

Error 1 error C2872: 'IServiceProvider' : ambiguous symbol C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\ocidl.h 8005


Among other files in the project, I had a header file which started like this:

using namespace System;
#include "MyHeader1.h"
#include "MyHeader2.h"


After a little research I have found the cause of this error. I turned on the /showIncludes option of the compiler and saw that one of my headers was actually including the "ocidl.h" file. The Build output will show, among others:
...
2>Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\atlcomcli.h
2>Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\olectl.h
2>Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack8.h
2>Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\ocidl.h
...

In order to fix this compile time error, I moved the using below the #include as below and it all started working again:
 
#include "MyHeader1.h"
#include "MyHeader2.h"

using namespace System;

Niciun comentariu:

Trimiteți un comentariu