"ccconsole.h, ccutf8.h error, expected a {"

Hello there, I have encountered a very problematic bug. I cannot build my project, because I keep getting these errors


Basically it gives of an error code that signifies there are missing braces/semicolons in the syntax.
These files though were not created by me and they are cocos2dx header files.
If someone could please visit these lines in those files and check what possibly could have happened it would be great.

This is how the lines look like for me:

ccutf8.h line 66

ccconsole.h line 63

what happens when you run cocos new ...? does that project build after you create it?

Does cpp-tests work for you?

Tell us how you installed Cocos2d-x.

I downloaded cocos2dx off of the cocos website, I ran the python set up file, set the android sdk and ndk root file paths. Then I went into windows powershell, ran cocos and then I ran the command

cocos new StarGameTest -p com.blabla.StarGameTest -l cpp -d D:/gameprojects

The project built and I ran cmake in the proj.win32 folder with the win32 configuration but this error still appears whether I am trying to build the solution or if I am just editing the source code files.

Cpp-tests worked perfectly for me without errors

The project build but you have these errors?

What modifications have you made to the project?

That’s probably the issue.

Don’t go into the win32.proj folder. Run CMake outside that folder.

For your case (assuming you’re using VS2019):

cd D:\gameprojects\StarGameTest
mkdir win32build
cd .\win32build
cmake .. -G"Visual Studio 16 2019" -Tv142 -A Win32

Then go into the win32build folder, and that will contain StarGameTest.sln, which is the correct solution file, along with the project files for Visual Studio.

1 Like

Basically, this error started appearing in an earlier project of mine, so I decided I would just build an entirely new project without making any notifications on it, and this error is still appearing despite.

Also a little update: the error actually does not make the build fail, and it occurs whenever I actually enter the source files in Visual Studio, when I close the source files the error does not list in the error list.

Good thoughts @R101

I did everything as you said but sadly the errors are still there. I do not know why they are there, considering log command works. I guess I can work with it but it may be signaling a problem with my installation and it will bug me.

Those errors in the screenshot are coming from some issue with your CMake generated project, being either missing files or resources.

When you run CMake, check for any warnings or errors. Go into \win32build\CMakeFiles\, and you’ll find the following files which you can open up and review for any problems:
CMakeError.log and CMakeOutput.log

If you are using the default CMakeLists.txt in the root of your game, and you add new resources (like graphics etc), then you need to go into the win32build folder, and delete CMakeLists.txt, then run the CMake command again to regenerate the Visual Studio solution files.

The alternative is to use a slightly modified CMakeLists.txt which no longer copies resources, but instead creates a symbolic link to them. The main benefit of this is that your Windows builds will be so much quicker (depending on how many resources you have).

Open up the root CMakeLists.txt in your game project folder, then scroll down to the bottom, where you’ll see this section:

if(LINUX OR WINDOWS)
    set(APP_RES_DIR "$<TARGET_FILE_DIR:${APP_NAME}>/Resources")
    cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})
endif()

Comment it out, and add this section instead:

if(LINUX OR WINDOWS)
    set(APP_RES_DIR "$<TARGET_FILE_DIR:${APP_NAME}>/Resources")
    add_custom_command(TARGET ${APP_NAME} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink ${GAME_RES_FOLDER} ${APP_RES_DIR})
endif()

(I can’t quite recall who originally posted this symbolic linking bit of CMake script, but it does really speed up development on Windows)

Just make sure you re-run CMake again. To make your life easier, add the following to a batch file, put it in your game project folder, and run it whenever you need to:

IF EXIST .\win32build\ GOTO STARTUPDATE
mkdir win32build
:STARTUPDATE
cd .\win32build
cmake .. -G"Visual Studio 16 2019" -Tv142 -A Win32
@REM cmake .. -G"Visual Studio 15 2017" -Tv141

Otherwise you can right-click on the “ZERO_CHECK” project when you have your solution loaded in Visual Studio, and build that specific project. It should also work.
image

1 Like

Actually this is a good tip. Perhaps i can use this as a tech tip

This forum is full of golden bits of info, but I think they just get buried over time. I’ve started adding them to a lightweight notes app that’s always running in the background, Tomboy Notes, just to save time searching for them.

if you are willing to share, I’ll create a post about all of them, we can pin it to our Knowledgebase category.

My CMake build has not generated any errors: This “{” problem appeared very arbitrarily. I reset my PC a few weeks ago and installed cocos2dx again, and everything worked, but a few days ago when I was working on one of my projects, this error appeared out of nowhere (the project I was working on already had hundreds of lines of code so it is not like this error appeared when I made a new project).

Can you please try this if you have the time: Go to this post, and download the test project. It’s for V4 of Cocos2d-x, and all it needs is for you to copy the cocos2d folder into it from one of your other projects. Run the VSUpdateCMake.bat file that’s in it, and open up the solution it creates in the win32build folder. Test that out.

If something is wrong with cocos2d-x on your PC, then this project should have the same issue. The project doesn’t show any errors when I compile it.

Since the project still gives me the same error, something has to be wrong with my cocos2dx installation.
I have reinstalled cocos2dx 2 times, but I think now I should try downloading the android SDK and NDK again, reinstalling CMake and possibly even reinstalling Python 2.7. I think there might be a problem with the NDK and SDK and CMake because I reset my PC, so I will tell you if I fixed this later.
Thanks anyways for the help :grinning:

Alright, nope. I reinstalled Python, I reconfigured the environment variables for Android, I have reinstalled CMake and reinstalled cocos2dx, this error is still occuring. I really do not know what to do and why this is happening.
How can an intellisense error pointing that a brace is missing be linked to anything?
I will try reinstalling visual studio at last but that is about it until I just give up and have to live with it.

What cocos2d-x version? VS 2019?

@lazarpuppet1 Use 3.17.2 version

I use Cocos2dx V4 and Visual Studio 2019.16