Trying to make CLion working with CMake and Cocos2DX

Just to understand better, but in this way I have to create a CMakeLists.txt myself?

  1. Build the cocos2d-x with CMakeLists.txt from sources :slight_smile:
  2. For you project (after ensure that cocos builds normally) you can use CMakeLists.txt provided by the generated project (but I don’t test this…). I use my own CMakeLists.txt file (only for desktop platforms). I can share it by request.

I think I’ve made some progress, I’m reading the setup for QT creator that you linked

Installed MSYS2, with pacman installed:

mingw-w64-x86_64-cocos2d-x-git
mingw-w64-x86_64-qt-creator
mingw-w64-x86_64-cmake 

Then I tried to open the Cocos Project with generated CMakeLists.txt and tried to build.
I’ve manually edited CMakelists for including all my .cpp and .h files:

set(GAME_SRC
  Classes/AppDelegate.cpp
...
...
...
  ${PLATFORM_SPECIFIC_SRC}
)

set(GAME_HEADERS
  Classes/AppDelegate.h
...
...
...
  ${PLATFORM_SPECIFIC_HEADERS}
)

I got some errors and fixed installing these:

mingw64/mingw-w64-x86_64-openal 1.16.0-2
mingw64/mingw-w64-x86_64-libvorbis 1.3.4-1
mingw64/mingw-w64-x86_64-glfw 3.1-1

Then I installed also the older version of chipmunk, because I got some errors in CCPhysicsBody.obj, manually downloading this:

mingw-w64-x86_64-chipmunk-6.2.1-1-any.pkg.tar.xz

Putting in MSYS2\var\cache\pacman\pkg and then installed with pacman -U

The compiling process continues for 70-80% of all cocos libs, some little warning but nothing special.

Now I’m stucked at this:

\myapp\cocos2d\cocos\platform\desktop\CCGLViewImpl-desktop.h:32: error: glfw3.h: No such file or directory
     #include "glfw3.h"

This header file is located here:

\myapp\cocos2d\external\glfw3\include\win32

But I think that path was not found correctly.

Could be a problem in CMakeLists? Maybe some FindPackages functions doesn’t work properly.

From the guide written by @Martell he uses this custom: https://github.com/martell/cpp-template-default/blob/master/CMakeLists.txt

It’s quite different from the recent CMakeLists generated by cocos2dx 3.6, I don’t know if yours CMakeLists will go better, I’m just discovering this new world :stuck_out_tongue:

BTW: I Forgot to say that Run CMake is ok, without errors.

Ok maybe I’ve done another progress.

When I run CMake I’ve not seen that pkg-config was not installed.

So I run:

pacman -S mingw64/mingw-w64-x86_64-pkg-config

And now it found GLFW3.

Now it’s continuing building, I’ll keep you updated…

@Levis

  1. Paths inside the \myapp\cocos2d\external folder should not be found. It’s because these libraries built with MSVC compiler. But you will use GCC compiler (mingw is a port of GCC that can generate windows executables) with other object files format.

  2. glfw3 should be found somewhere inside msys folders. If not, something is wrong, but I can’t say what specifically from the information you provided.

  3. Cocos CMakeLists.txt files print the information about found libraries and paths when you run cmake tool. Can you see where its found GLFW (or not found)?

When I found some spare time (in a day or two), I try test cocos with MSYS2 again (I stop doing that after upgrading chipmunk pacakge).
Also I will try to prepare the sample project that we use in our team.

Ah, ok :smile:

Really thank you, maybe today I’ll try to finish this build :stuck_out_tongue:
If so I’ll keep the community updated, writing the last steps for building also in CLion… (ahhh long way :smile: )

Anyway really thank you for answering me.

Now the build seems ok, but during linking libs got this:

In my project I’m using rapidjson, but I don’t know if it’s related to this or to other things, now I’ll try to rebuild all with an helloworld project maybe it’s simpler and I don’t get this error.

Checked also if it was tinyxml2 prob, I’ve installed this:
mingw64/mingw-w64-x86_64-tinyxml2 2.2.0-1

I’ve tried also with a standard helloworld project, and got this:

Maybe something else I’ve forgot to install?

Tried to reinstall from zero all with msys2 and all libs i686, so not x64.
After all the build and compile I got the same identical error as shown above.

For now I give up, no other ideas :frowning:

Hello. I’m newbie in cocos2d programming. I coming from as3 development and always used Intellij Idea IDE. And I became very happy when discovered that post about making cocos2d work with CLion. It is very sad for me that it doesn’t work yet, but you did good job. I’m very appreciated for all you have done.

I’m a newbie in C++ (and in English too :smile: ) and I found the following solution. You can include tinyxml2.cpp and tinyxml2.h in CMakeLists.txt

elseif ( WIN32 )
set(PLATFORM_SPECIFIC_SRC
  proj.win32/main.cpp
  Classes/tinyxml2.cpp
)
set(PLATFORM_SPECIFIC_HEADERS
  proj.win32/main.h
  Classes/tinyxml2.h
  proj.win32/resource.h
)
endif()

mingw doesn’t have _get_wpgmptr so you can do this in CCFileUtils-win32.cpp

static void _checkPath()
{
    if (0 == s_resourcePath.length())
    {
        /*WCHAR *pUtf16ExePath = nullptr;
        _get_wpgmptr(&pUtf16ExePath);

        // We need only directory part without exe
        WCHAR *pUtf16DirEnd = wcsrchr(pUtf16ExePath, L'\\');

        char utf8ExeDir[CC_MAX_PATH] = { 0 };
        int nNum = WideCharToMultiByte(CP_UTF8, 0, pUtf16ExePath, pUtf16DirEnd-pUtf16ExePath+1, utf8ExeDir, sizeof(utf8ExeDir), nullptr, nullptr);

        s_resourcePath = convertPathFormatToUnixStyle(utf8ExeDir);*/

        s_resourcePath = YOUR_PATH_TO_RESOURCES_DIR;
    }
}

for Clion something like this “c:/Users/[USERNAME]/.clion10/system/cmake/generated/be9fed93/be9fed93/Debug/bin/Resources/”

It’s awful, but it works for me.

Thank you @romsvm I’ll try as soon as possible this solution!

Ok now I’ve solved almost all the problems.

Thanks @romsvm for the suggestion on tinyxml and resources!

I’ve only some little problems when I use resources in subfolders, maybe some other tweaks and I think it is ok.

I have written a little guide with all the steps, when this last step is resolved I’ll make a post, so also other ppl can compile with CLion!! YEAH! :smile:

Debug works too!!!

Updated step by step:

Need to resolve the Resources problem, really awful :frowning: even if the solution proposed by @romsvm is working

I had try “Levis” 's method, I encount some problem:
…msys64/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/5.2.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: cannot find -lbullet
…msys64/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/5.2.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: cannot find -lrecast

how to fix it?

I’ve just updated Cocos v3.9 and I have tried a new compile, without success.
The same error like you.

Furthermore it seems that: mingw-w64-x86_64-cocos2d-x-git no longer exists

So I have to install more things:

pacman -S mingw-w64-x86_64-openal mingw-w64-x86_64-libvorbis mingw-w64-x86_64-glfw mingw-w64-x86_64-pkg-config mingw-w64-x86_64-glew mingw-w64-x86_64-mpg123 mingw-w64-x86_64-freetype mingw-w64-x86_64-libwebp mingw-w64-x86_64-tinyxml2 mingw-w64-x86_64-libwebsockets mingw-w64-x86_64-xxhash mingw-w64-x86_64-flatbuffers mingw-w64-x86_64-bullet

I have found only bullet library in mingw, but not recast.
Anyway the errors after linking are both for Bullet and Recast

Somebody have fixed this?

cocos2dproj.zip (7.3 KB)
Hey, Levis! I had uploaded my cmake config file. you can try it.

no need to install package that list below:
tinyxml2
xxhash
flatbuffers
bullet

the only two big problem by now I encount is that the libcocos2d.a library file and the target MyGame.exe file are too large, and building project is slow.

2 Likes

Thank you I’ll try soon the -fpermissive flag!

Hey Ricardo, I’ve tried using CMake make/ninja to build a fresh Cocos2d-x game project on OS X / Linux and never had success. Is there a suggested way to setup the cmake OS X/Linux build, or should I read through the replies here and try to sort it out? I’m currently getting the same '‘glfw3.h’ file not found" error as the user here.

Simply put, are there any steps other than running cmake on the CMakeLists.txt and then building?