Qt Creator and Mac: Setup

Qt Creator and Mac: Setup
0.0 0



I think Qt Creator is the best way to do cross-platform dev for C++ and am trying to setup Qt Creator and cocos2d-x on a Mac. Has anyone else done this?

I have tried looking up the instructions on the wiki (http://www.cocos2d-x.org/wiki/QtCreator_project_setup_on_Linux), however that’s Linux-specific. I get this error on build:

/Users/kid/qt/juiv/proj.linux/main.h:5: error: ‘CCStdC.h’ file not found
#include “CCStdC.h”

Any guidance would be deeply appreciated. Once I get it working, I will definitely make it into a guide for others.



As you’ve seen on wiki, QtCreator allows to include .pri and .prf files into project file; this feature used in cocos2d. However only linux support was added, so you have to edit following files and add OSX support to:
* CocosDenshion/proj.linux/CocosDenshion.prf
* extensions/proj.linux/extensions.prf
* external/Box2D/proj.linux/box2d.prf
* external/chipmunk/proj.linux/chipmunk.prf
* cocos2dx/cocos2dx.prf
* cocos2dx/cocos2dx.pri

First 5 files call make on existing Linux makefile (standard way to build cocos2dx on Linux), they also link application with built libraries. I’ve also put them to linux { ... } section which works when QtCreator (qmake) builds project for linux; for OSX also add another macx { ... } section. In this section add similar code which calls xcodebuild command-line utility with appropriate options. More details on xcodebuild:
* https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html
* http://stackoverflow.com/questions/9527058/how-can-i-use-xcodebuild-in-command-line

File cocos2dx/cocos2dx.pri adds macro defines and headers search paths (INCLUDEPATH), which are platform-dependent, so you again have to add macx { ... } section with OSX defines and include paths, something like.

*macx-* {
    INCLUDEPATH += $$PWD/../platform/mac
    LIBS += -lpthread

I don’t know where xcodebuild puts build result by default, and how to set custom path (similar to ${COCOS_ROOT}/lib/linux/{debug|release}), so I suggest you to experiment.

P.S. Oh I forgot, OSX uses clang compiler and libc++ C*+ standard library for C**2011 support, but you should explicitly tell qmake to use libc++:
<pre>macx-clang {
QMAKE_CXXFLAGS*= -stdlib=libc++

More details: http://stackoverflow.com/questions/14749315/clang-under-qtcreator-cant-work-with-c11


Thanks for the detailed response Sergey! That was great and I managed to edit the files and build a Mac app!

Here’s the addition I made to cocos2d.prf:

  *macx-* {
    CONFIG(debug, debug|release) {
        # Override in debug build.
        CC_MAKE_FLAGS += DEBUG=1
        CC_LIBRARY_DIR = $$COCOS2D_ROOT/lib/mac/debug
    contains(COCOS2D_MODULES,box2d) {
        CC_MAKE_FLAGS += USE_BOX2D=1
    !equals(COCOS2D_USE_FMOD, 1) {
    CC_LIBRARY_DIR = $$COCOS2D_ROOT/lib/mac/release
    CC_MAKE_FLAGS = -scheme \"cocos2dx Mac\"
    build_cocos2d.name = Build cocos2d shared library
    build_cocos2d.input = $$COCOS2D_ROOT/cocos2d_libs.xcodeproj
    build_cocos2d.output = $$CC_LIBRARY_DIR/"libcocos2dx Mac.a"
    build_cocos2d.target = $$CC_LIBRARY_DIR/"libcocos2dx Mac.a"
    build_cocos2d.commands = xcodebuild -project $$COCOS2D_ROOT/cocos2d_libs.xcodeproj $$CC_MAKE_FLAGS CONFIGURATION_BUILD_DIR=$$CC_LIBRARY_DIR
    QMAKE_EXTRA_COMPILERS += build_cocos2d
    QMAKE_EXTRA_TARGETS += build_cocos2d
    PRE_TARGETDEPS += $$CC_LIBRARY_DIR/"libcocos2dx Mac.a"
    LIBS += $$CC_LIBRARY_DIR/"libcocos2dx Mac.a"

Here’s the addition to cocos2d.pri

  *macx-* {
    QMAKE_CXXFLAGS += -std=c++11
    QMAKE_CXXFLAGS += -stdlib=libc++
    INCLUDEPATH += $$PWD/../platform/mac
    LIBS += -lz
    LIBS += -framework IOKit -framework OpenGL -framework AppKit -framework Foundation -framework QuartzCore -framework OpenAL -framework AVFoundation -framework AudioToolbox

And here’s a sample addition to one of the submodules:

 *macx-* {
    CC_MAKE_FLAGS = -scheme \"CocosDension Mac\"
    build_CocosDension.name = Build CocosDension shared library
    build_CocosDension.input = $$COCOS2D_ROOT/cocos2d_libs.xcodeproj
    build_CocosDension.output = $$CC_LIBRARY_DIR/"libCocosDension Mac.a"
    build_CocosDension.target = $$CC_LIBRARY_DIR/"libCocosDension Mac.a"
    build_CocosDension.commands = xcodebuild -project $$COCOS2D_ROOT/cocos2d_libs.xcodeproj $$CC_MAKE_FLAGS CONFIGURATION_BUILD_DIR=$$CC_LIBRARY_DIR

    QMAKE_EXTRA_COMPILERS += build_CocosDension
    QMAKE_EXTRA_TARGETS += build_CocosDension

    PRE_TARGETDEPS += $$CC_LIBRARY_DIR/"libCocosDension Mac.a"
    LIBS += $$CC_LIBRARY_DIR/"libCocosDension Mac.a"

Do you want me to submit this code as a pull request? And, do you want to move th pri and prf files outside of the proj.linux subdirectory and make a new one, for example: proj.qmake or proj.qtcreator?

The cool thing about Qt Creator is that it understands C++ very well and I don’t have to do the crazy setup routine that is needed for Eclipse+CDT.

Next: integrate the doxygen docs.



Excellent, thanks a lot! I think pull request isn’t needed, since there was big refactoring in cocos2d-x develop branch a few days ago, build for Linux port temporary broken and I’m going to rework it using qmake and QtCreator instead of makefiles.

New QtCreator project will be no longer placed in proj.linux and will use just /build/qtcreator. I’m also going to add support for Windows and Mac using your additions.

There also was Qt5 port which was removed after refactoring, maybe I’ll return it back later as part of single multiplatform project inside /build/qtcreator.


I have a problem with running cocos2d-x project on mac with qtcreator. I read solutions in this topic and apply it, but when I run hello world project my application crash with “Segmentation fault: 11” on Director::setOpenGLView, this is the Stack Trace:

0 glGetString
1 cocos2d::Configuration::gatherGPUInfo()
2 cocos2d::Director::setOpenGLView(cocos2d::EGLView*)
3 AppDelegate::applicationDidFinishLaunching()
4 cocos2d::Application::run()
5 main
6 start

When I try run my project on Ubuntu I have the same. The application run with console and any window appear , so I think that glContex was never created. Anybody know how to fix it? When I run project with Xcode it works.


Has somebody tried to configure QtCreator for Mac with Cocos2d-x v3.0? All .pri/.prf files have been removed from the library.

Thanks a lot in advance


cocos2d-x v3 use cmake for linux build ,and qtcreator can use cmake project directly.
and also on mac ,you can use qtcreator to build it use cmakefiles


cmakefile do not work on QT mac