Compiling error

Hey guys,

There is a new compile error on cocos2d-x git in relation to UIButton.

/ui/UIButton.cpp:41:26: error: definition of static data member ‘cocos2d::ui::Button::__Type’ of dllimport’d class
 IMPLEMENT_CLASS_GUI_INFO(Button)
                          ^
C:/msys64/home/Martell/MINGW-packages/mingw-w64-cocos2dx-git/src/cocos2d-x/cocos/ui/GUIDefine.h:45:35: note: in definition of macro ‘IMPLEMENT_CLASS_GUI_INFO’
     cocos2d::ObjectFactory::TInfo className::__Type(#className, &className::createInstance);
                                   ^
cocos/ui/CMakeFiles/ui.dir/build.make:77: recipe for target ‘cocos/ui/CMakeFiles/ui.dir/UIButton.cpp.obj’ failed
make[2]: *** [cocos/ui/CMakeFiles/ui.dir/UIButton.cpp.obj] Error 1
CMakeFiles/Makefile2:328: recipe for target ‘cocos/ui/CMakeFiles/ui.dir/all’ failed

I can’t create a ticket for some reason so I have to post it here

@zhangxm any ideas?

Cheers
Martell

It seems it’s related to this commit

I will have to create a solution where we can choose between a static and dynamic version

Thanks Martell!
Could you please show us how to reproduce this compile error?

Hi @dabingnn

It is due to the CMakeLists.txt creating a static lib even though visual studio projects have been changed to build dynamic libraries.

To reproduce the error.
I ran the makepkg with pacman to build this for mingw64 so it is a windows gcc build.
The same issue will occurs when cmake is used with visual studio however so it is important to fix.

I’ll be adding a guide to build it from source via cmake then i suppose you guys can add this to your build test cases

I will make a PR to fix this shortly.

@Martell, Thanks.
Now CMake is only used on Linux. Others are using their specific project file, such as sln file for Visual studio, xcodeproj for Xcode.
I heard that @zhangxm is working on migrating project management into CMake on all platforms. It is still unfinished. And your help and suggestions is highly appreciated.

@Martell
What i am doing is that

  • just have one static library for c++ codes and another one for lua-bindings
  • i almost finish it on linux platform which means i will modify CMakeLists.txt and may make it not work on Windows because now i am not familiar how to use CMake to generate VS projects
  • I will try to use CMake to generate project files for all platforms, makefile on linux, XCode project on Mac OS X, and VS on windows, but it may take me some time to do it

So could you please do the work after we releasing v3.3alpha0? We will make all project settings on all platforms, to let all c++ codes in one lib and all lua-bindings in another one lib.

Hi @zhangxm,

I already have CMake working on mac and Windows.
I just haven’t done a PR for it.

I can combine all the source files into one static library but that would require a restructure of all the CMakeLists. It is a task that can be done fairly easily enough however. I agree we should leave that for after the next version

I’ll do a PR to add support for these 2 platforms.
I will leave the project as is however and suggest everyone still uses the included vs and xcode projects.

I now have a PR ready for this.

Hey @Martell,

You mention that you have it working for Mac as well. Is that confirmed and will it be included as part of your PR?

I am trying to get Qt Creator to open cocos2d-x CMakeList.txt but CMake throws up errors about the audio and the c++11 parts. I am guessing that it assumes that the OS is Linux.

Hi @kidproquo,

I don’t have access to a mac atm but i did have this working on mac in the past.
The structure have changed in the project since then so I would have to redo it.

I willl probably have to split this into 2 PR’s to do that.

I’m currently adjusting to have it all compile into one library.
After that I will have a go at doing that :wink:

Having unified cmake is great news! Thanks @Martell

However, the PR that has been merged broke two things:

  • WP8 doesn’t link any more. The CocosDenshion symbols aren’t being recognized anymore. Perhaps related to CC_STATIC ?

  • cmake on Mac is not working anymore… or at least not when I execute this:

    $ mkdir mac && chdir mac
    $ cmake …
    $ make -j8 cpp-tests

Any ideas?

Mmmm…

and cmake in Linux seems to be broken as well :frowning: It can’t find “glfw3.h” although I have installed it with the “build/install-deps-linux.sh”

Just to clear this up for the forum.

WP8 was broken before I introduced the CC_STATIC MACRO.
It was broken when shared dll’s were enabled for windows.
I added CC_STATIC to the project for this reason.
A PR has been merged to enable CC_STATIC for WP8 to avoid she dllimport and dllexport errors

CMake for Mac will work when the prebuild libs are done properly for that platfrom.
All the CMake code is ready for that landing

When rebasing my patches I somehow lost FindGLFW.cmake from the repo.
That has been re added and merged which fixes linux.
That one was my bad :smiley:

Thanks @Martell

BTW, can you tell me how to test cmake on windows ?
I’m a newbie windows user (actually I was a very proficient windows developer some years ago, but I forgot everything and now I’m re-learning everything) and I’m not sure what to install in order to test cmake on win. thanks.

Sure, I’ll jump onto irc and go through it with you :slight_smile: