Question

i'm novice in this, can u give me some suggests ? So i want to make a simple multi platform app with SDL and qt.

Problem is:

on windows_  #include <SDL2/SDL_main.h>
on mac_      #include <SDL_main.h>

cause on windows all libraries in folders inside "include" folder, on mac inside /Library/Frameworks So i want to know how better make includes... is i need on all platforms make one view like or exists better practice ? also i don't use cMake for this.

Example Mac:

*.Pro file
INCLUDEPATH += /Library/Frameworks/SDL2.framework/Headers
QMAKE_LFLAGS += -F/Library/Frameworks/
LIBS += -framework SDL2

#include <SDL.h>

Windows:

*.Pro file 
INCLUDEPATH += C:\SDL2-2.0.1\i686-w64-mingw32\include
LIBS += -L"C:\SDL2-2.0.1\i686-w64-ming32\lib" \
-lmingw32\
-lSDL2main\
-lSDL2

#include <SDL2/SDL2.h>

So how better make main.cpp that on all platforms it was one path or it's exists something like if win32 path else ?

Was it helpful?

Solution

In an ideal world, you should use the same code, and the buildsystem should make the buildsystem related data just work.

You could use the following scopes in your qmake project file:

mac: INCLUDEPATH += mac-specific-include-path
unix: INCLUDEPATH += unix-specific-include-path
win32: INCLUDEPATH += win32-specific-include-path

etc...

The source code will include the header files like this, then:

#include <SDL_main.h>

I would suggest to leave out the module prefix because that may hide bugs in the build system. That being said, in some projects you need to follow the convention regardless what looks more reasonable to someone.

This will ensure that if you switch port your code to another platform, you will need to make the code more complex that you probably read and modify often as the maintainer.

For sure, this also had the disadvantage that you need to reimplement this logic if you switch to a new buildsystem like cmake or QBS, but I would still recommend solving these issues on the buildsystem layer because nice source code is important.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top