"cocos2d is ambiguous" error in Visual Studio

I just created a new cocos2d-x c++ project and opened the solution inside proj win32 folder (in visual studio 2015). Everything is ok, it runs normally on android and windows platforms. But this code is underlined with red:
using namespace cocos2d;
The error is: “cocos2d is ambiguous”. The project build and runs perfectly but because of this error i can’t use code completion and it doesn’t recognize my code. Almost everywhere is underlined with red.

My english is not perfect and I hope you understand my problem. Thanks in advance.

4 Likes

I’ve got the same problem. If you 've solved it can you show the way?

I have same issue but only on Visual Studio 2015. In VS 2013 everything its ok. Do you guys have installed VS 2013 and 2015 same as me ? or only Visual Studio 2015?

I use Visual Studio 2015

i’m not using VS 2015, but ambiguous may because you are using namespace cocos2d; and USING_NS_CC;
but it is fine in VS 2013 anyway. i’m just guessing.

I have got the same problem with cocos 3.15 after unistalling cocos 3.8 framework thats weird !

Please someone provide a solution

guys , i don’t know why but
adding #include <ui/UIButton.h> on the top of cpp file solves the problem )
i am even don’t use buttons in some files, and later you can delete the line added, maybe it is intellisence bug

1 Like

I’ve got the same problem.
I use 3.16 with vs2017.
the similar problem some other said,on stackoverflow (we can search visual-studio-2015-win-7-32-cocos2d-is-ambigious-but-still-compiled-and-run)
If you 've solved it can you show the way?

Changing from #include "cocos2d.h" to #include <cocos2d.h> should fix your issues.

1 Like

The problem is still in my case. Ohter solutions?

It’s Visual studio issue with the intellisense atm. Either try to get older downgraded or check if the newest version fixed the issue. ( 15.6v - Downloading so I will know it soon if it was fixed).
As a workaround for me I just changed the #include <cocos2d.h> to be used and always deleting 1 line and re-saving so that file would be picked up by the Intellisense then it works. (Have to do always on the header file first when opening the project).

EDIT:
Newest version didn’t fixed for me. However as I can confirm (atleast in my situation) there is a workaround.
Chaning into #include <cocos2d.h> is not needed. You only need to make 1 line modification first in the header file (.h) in the file you are working and then in the method class file (.cpp) and it will fix that issue temporaly (until you close the project). You can just hit Enter for a new line and it should be enough to force Intelisense to fix that class file. However, it’s still annoying to do if you have alot of class files…