简体   繁体   中英

Linking SDL2 in QtCreator

So I want to use Qt as an editor for my SDL app. When I try to make even just a blank project in Qt and link up the libraries, it just can't find SDL2/SDL.h. Here is whats inside my .pro file:

mac: LIBS += "-F$$PWD/../Control Libraries/" -framework SDL2
INCLUDEPATH += "$$PWD/../Control Libraries/SDL2.framework/Versions/A/Headers"


mac: LIBS += "-F$$PWD/../Control Libraries/" -framework SDL2_mixer
INCLUDEPATH += "$$PWD/../Control Libraries/SDL2_mixer.framework/Versions/A/Headers"


mac: LIBS += "-F$$PWD/../Control Libraries/" -framework SDL2_ttf
INCLUDEPATH += "$$PWD/../Control Libraries/SDL2_ttf.framework/Versions/A/Headers"

I can't find anyone who has posted how to get this to work, but I know there has to be some way. It works in Xcode with one click, so am I just doing something wrong? Thanks.

EDIT:

Here iss the error message:

    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.6 -Wall -W -fPIE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../../../Qt/5.3/clang_64/mkspecs/macx-clang -I../SpudEngineEditor -I../Control\ Libraries/SDL2.framework/Headers -I../Control\ Libraries/SDL2_mixer.framework/Headers -I../Control\ Libraries/SDL2_ttf.framework/Headers -I../../../Qt/5.3/clang_64/lib/QtWidgets.framework/Versions/5/Headers -I../../../Qt/5.3/clang_64/lib/QtGui.framework/Versions/5/Headers -I../../../Qt/5.3/clang_64/lib/QtCore.framework/Versions/5/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I. -F/Users/Logan/Qt/5.3/clang_64/lib -o Camera.o ../SpudEngineEditor/Camera.cpp
In file included from ../SpudEngineEditor/Camera.cpp:9:
In file included from ../SpudEngineEditor/Camera.h:13:
../SpudEngineEditor/CoreEngine.h:14:9: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma comment (lib, "glu32.lib")
        ^
In file included from ../SpudEngineEditor/Camera.cpp:9:
In file included from ../SpudEngineEditor/Camera.h:13:
In file included from ../SpudEngineEditor/CoreEngine.h:34:
../Control Libraries/SDL2_ttf.framework/Headers/SDL_ttf.h:30:10: fatal error: 'SDL2/SDL.h' file not found
#include <SDL2/SDL.h>

EDIT: I've gotten it so I can include , but not , which is a problem because SDL mixer and SDL rtf both use

You should use double quotes when paths have spaces in them, for example:

INCLUDEPATH += "$$PWD/../Control Libraries/SDL2.framework/Versions/A/Headers"

Unless you do want them to be separate arguments, for example:

mac: LIBS += "-F$$PWD/../Control Libraries/" -framework SDL2_mixer

After question edit: So you have #include <SDL2/SDl.h> . It seems to have wrong case, should probably be

#include <SDL2/SDL.h>

The compiler is clear about the error:

../SpudEngineEditor/main.cpp:3:10: fatal error: 'SDL2/SDl.h' file not found

What you ought to do is to replace this line:

#include <SDL2/SDl.h>

with:

#include <SDL2/SDL.h>
//               ^, yes uppercase.

Also, as for the paths with whitespaces, you ought to use for instance the corresponding quote qmake function established for this purpose, which will also work with double quotes inside. Double quotes might work, too, in all cases, but I personally prefer the fancy function if there is one established. :-)

I would also establish an auxilliary variable if I were you not to repeat the same path a couple of times.

Furthermore, I would write a qmake function, although that is not necessary with inline calls, that uses the real qmake power, the for loop since you are repeating the same thing. Thereby, I would be writing something like this:

setSDLPaths() {
    CONTROL_LIBRARIES_PATH = $$quote($$PWD/../Control Libraries/)
    LIST = SDL2 SDL2_ttf SDL2_mixer
    for(item, LIST) {
        mac: LIBS += -F$$CONTROL_LIBRARIES_PATH -framework $$item
        INCLUDEPATH += $$CONTROL_LIBRARIES_PATH/$${item}.framework/Versions/A/Headers
    }
}

which then would simplify your code a lot, basically to a one-liner:

$$setSDLPaths()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM