1

My friend and I are porting our software to Mac OSX. The application is heavily built on SDL and we are having a hard time getting SDL linked and compiling in Qt5. We are not using any part of Qt in our code other then using the IDE for cross-platform ease.

Currently, I have SDL framework inside /Library/Frameworks/

Inside application.pro I have:

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

macx {
   INCLUDEPATH += "/Library/Frameworks/SDL.framework/headers/"
}

In main.cpp I obviously have #include "SDL.h" and if I ctrl Click on the SDL.h it shows that it is linking to the framework...

When I go to build/compile I get this error:

14:21:24: Running steps for project BDGame...
14:21:24: Configuration unchanged, skipping qmake step.
14:21:24: Starting: "/usr/bin/make" -w
make: Entering directory `/Users/Kite/Dropbox/Wizardry Games/BDGame/BDGame-build-Desktop_Qt_5_0_0_clang_64bit_SDK-Release'
g++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o BDGame main.o    
Undefined symbols for architecture x86_64:
  "_main", referenced from:
      start in crt1.10.6.o
     (maybe you meant: _SDL_main)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [BDGame] Error 1
make: Leaving directory `/Users/Kite/Dropbox/Wizardry Games/BDGame/BDGame-build-Desktop_Qt_5_0_0_clang_64bit_SDK-Release'
14:21:24: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project BDGame (kit: Desktop Qt 5.0.0 clang 64bit (SDK))
When executing step 'Make'

enter image description here

What am I doing incorrect that is stopping Qt from using SDL?

NG_
  • 6,895
  • 7
  • 45
  • 67
John Riselvato
  • 12,854
  • 5
  • 62
  • 89
  • It looks like your SDL libs do not have 64 bit versions in the framework and you are building 64 bit. Do a make clean and make sure all object files/libraries are rebuilt under MacOS before continuing. You should be able to build 32 bit if you add "CONFIG -= x86_64" and "CONFIG += x86" to your pro file. – koan Dec 26 '12 at 19:02
  • I tried this, but that didn't seem to change anything. – John Riselvato Dec 26 '12 at 19:24
  • You are clearly trying to link to Intel 64 bit architecture, that's why you get the message "ld: symbol(s) not found for architecture x86_64". I don't use creator but you show 32 bit PPC architecture selected in the screenshot with 64 bit clang selected. Your compiler should be either "Clang (x86 64bit)" or "GCC (x86 64bit)" – koan Dec 27 '12 at 01:27

1 Answers1

3

In your main.cpp file you have to declare int SDL_main(int, char**) function instead of main(). You also need to get SDLMain.h and SDLMain.m files distributed along with SDL bundle for OS X. These two are required to bootstrap your Cocoa application that will invoke further the SDL_main function.

I suppose you use Qt project (*.pro) file. You should have something like this in yours:

qtsdl.pro

QT       -= core gui

TARGET = qtsdl
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

INCLUDEPATH += /Library/Frameworks/SDL.framework/Headers
LIBS += -framework Cocoa -framework SDL

SOURCES += \
    main.cpp

OBJECTIVE_SOURCES += \
    SDLMain.m

HEADERS += \
    SDLMain.h

main.cpp

#include <SDL.h>

int SDL_main(int argc, char *argv[])
{
    (void)argc;
    (void)argv;

    SDL_Surface *screen;

    if (SDL_Init(SDL_INIT_VIDEO) < 0)
        return 1;

    screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL | SDL_HWSURFACE);
    if (!screen) {
        SDL_Quit();
        return 1;
    }

    SDL_Event event;
    bool running = true;

    while (running) {
        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_QUIT:
                running = false;
                break;
            case SDL_KEYDOWN:
                running = false;
                break;
            default:
                break;
            }
        }
    }

    SDL_Quit();
    return 0;
}

SDLMain.h and SDLMain.m take them from SDL framework distribution.

Archie
  • 2,644
  • 21
  • 21
  • This seems to have produced a new issue; `:-1: error: No rule to make target `SDLMain.m', needed by `SDLMain.o'. Stop.` Unfortunately I don't understand it. – John Riselvato Dec 27 '12 at 00:13
  • Have you copied SDLMain.h and SDLMain.m files to your project? You can find these files in devel-lite folder of SDL-xxx.dmg archive used to install SDL framework. – Archie Dec 27 '12 at 00:30
  • Yes. I did and that seemed to help i guess. but you'll like what happened next. http://i47.tinypic.com/2rm7d4n.png – John Riselvato Dec 27 '12 at 00:31
  • You have to link Cocoa framework as I showed above. I have three files in my project SDLMain.h, SDLMain.m (coming with SDL framework) and main.cpp that includes SDL.h and declares SDL_main(). – Archie Dec 27 '12 at 00:40
  • Archie, can you send me your working SDL QT Project (simple hello world equivalent)? I have my cocoa framework linked as above. If you have working code, and it doesn't work on my side, its probably something still wrong wit my set up. If it does work, well then I'll be able to use your code as reference. – John Riselvato Dec 27 '12 at 00:46
  • I see you updated your code, I have exactly what you have and now I am getting the same 'error: symbol(s) not found for architecture x86_64' this is my new command `g++ -headerpad_max_install_names -mmacosx-version-min=10.6 -F/Library/Frameworks/ -o qtsdl main.o main.o -framework Cocoa -framework SDL` – John Riselvato Dec 27 '12 at 01:10
  • Fixed it, your stuff is completely correct, I was actually getting issues to the the win32 that was inside my .pro file. Thank you very much +1 and accepted. – John Riselvato Dec 27 '12 at 01:32