Sdl Clion

Dear users!

  1. Sd Clinic
  2. Sl Clinton
  3. Sd Clone

I want to develop simple games for PC (Windows, Mac and Linux). I already have made some small games on Linux using SDL.
The last days I tried to setup a CMake Cross Platform SDL App - with success!
With the following guide (SDL2 with CMake) I created a CMake SDL Project which build on Windows, Mac and Linux.
On Windows I am working with Visual Studio (like in guide) and on Linux/Mac I am working with CLion.

After the actions described in my comment everything worked fine and SDL.h wasn't red on my side, so CLion is capable of working with SDL library. What version of CLion do you use? What SDL distribution have you installed? Please reload the CMake project (Tools CMake Reset Cache and Reload Project) and show the full output that you get in the CMake tool window.

Greetings!PyCharm is an IDE I'm quite familiar with, so when (again) starting with C/C it was only natural to take a peek at CLion (nice timing to pushing out the 1.0 btw).But I'm running into tr. I did not use the last two commands. Instead, I just compiled (a really simple program to test sdl) with: g myTest.cpp -o myTest -lSDL2 And then ran the test with./myTest If you are using CLion, just add at the end of the CMakeList: targetlinklibraries(PROJECTNAMEHERE SDL2). Contribute to DanqueDynasty/SDLDemo development by creating an account on GitHub. After going through this video you should be able to get started programming SDL2 on CLion. Some of these steps are generic and the information may work (gen.

My CMakeLists.txt file has the following content:

And is linked to the .cmake file from the linked guide, that searches for SDL on the system:

On Windows I created a Visual-Studio Project with the CMake-Gui. When I run it, it only needs the SDL2.dll file in the same path as the generated .exe-file. In Visual Studio, I linked all the .dll-dependencies needed to my .exe-file (properties / Configuration / C/C++ / Code Generation / Runtime library / Multithreaded). Then I copied my .exe file and the SDL2.dll file to another Windows Computer to see, if the SDL App would start and yes, it worked!

Sd Clinic

Now I need the same for Linux/Mac, I already tried running the SDL App on my sisters MacBook but it says it can’t find the sdl-framework. How can I set it up that the sdl-framework needed libraries are linked to my executable-file in Mac/Linux? What do I have do add to my CMakeLists.txt-File to build id properly with all the dependencies so it works on a non-SDL Linux/Mac system? I also read about, that I need to include a .a or .dylib file as they are the equivalent to the .dll-files on windows but I was not able to find these files (something like SDL2.a or SDL2.dylib (?)). I also studied A LOT threads but a lot of them were old or didn’t build the project with cmake, so they didn’t help me either…

Could someone help? I would much appreciate any help how I can run my Mac/Linux CMake-SDL App on Mac/Linux w/o SDL or any other needed lib installed. I tried so much but wasn’t successful.

Sl Clinton

Thank you guys!

the source code of my SDL App (testing):


The documentation of SDL mentions on Mac “You can ship an SDL.framework, or just build the .dylib file and ship it with an appropriate install_name to ship beside your program’s binary.” How does this work? How can I make that with my SDL App?

And how does this work on Linux?

BUT it also says on the wiki under static linking ' SDL 2.0, unlike 1.2, uses the zlib license, which means you can build a static library linked directly to your program, or just compile SDL’s C code directly as part of your project. You are completely allowed to do that. However, we encourage you to not do this for various technical and moral reasons'. How can I make my SDL2 App then runnable on other platforms, without static linking on Mac/Linux?


The only thing I met that somehow is like my problem was the follwing post from 2005: SDL under MacOSX. But that didn’t help me either…


Ony my Mac, i found the mentioned files libSDL2-2.0.0.dylib, libSDL2_test.a, libSDL2.a and libSDL2main.a under /usr/local/Cellar/sdl2/2.0.9_1/lib. I copied the files the build folder where the binary-executable is stored. Then I tried to run it on my sisters Mac but still, I get the same error dylib: Library not loaded: @rpath/SDL2.framework/Versions/A/SDL2.


After a lot more searching, i found a recently post on this forum: Creating an Easily Distributable Executable File. As the discusssion progresses, it says that it is indeed not easy to setup everything for Mac or Linux. Altough there are some working ideas, I think it is not worth it for me to make the game for non-installed SDL for Mac/Linux as it would require me to get more into that topic. I think the easiest way for me is to just build for Windows. Potentially a solution on Mac could be using an install-setup to move the sdl2.framwork files to the /Libray/Frameworks folder, but I don’t know if this is even possible.

As long as there is not a complete “easy” tutorial for people like me I guess it is not worth the effort since I don’t wanna waste to much time on this. However, I learned some new things.

Sdl Clion
1)First thing you need to do is download SDL headers, libary and binaries. You will find them on the SDL website, specifically on this page.
You'll want to download the MinGW development libraries.
Open the gzip archive and there should be a tar archive. Open up the tar archive and the should be a folder called SDL2-2.something.something. Inside of that folder there should be a bunch of folders and files, most importantly i686-w64-mingw32 which contains the 32bit library and x86_64-w64-mingw32 which contains the 64bit library.
This is important: most compilers still compile 32bit binaries by default to maximize compatibility. We will be using the 32bit binaries for this tutorial set. It doesn't matter if you have a 64bit operating system, since we are compiling 32bit binaries we will be using the 32bit library.
Inside of i686-w64-mingw32 are the include, lib, and bin folders which contain everything we need compile and run SDL applications. Copy the contents of i686-w64-mingw32 to any directory you want. I recommend putting it in a folder that you dedicate to holding all your development libraries for MinGW. For these tutorials I'm putting it in a directory I created C:mingw_dev_lib
2)Next you're going to want to get up the path for mingw so you can run mingw commands in any directory. Open up the system menu either by A) right clicking My Computer and selecting Properties or B) going to the Control Panel and selecting the system menu. Once your in the system menu, click advanced system settings.
and then click environment variables
Under system variables, select the 'Path' variable and click edit.
What the path variable does is tell the OS where to look when running an executable. What we want to do is whenever we run the g++ command, the OS should look in the MinGW bin directory where g++.exe is located. If you installed MinGW by itself, the MinGW bin directory should be
Append it to the long list of paths with a semi-colon after it and click ok. If you're using an IDE like Code::Blocks which uses MinGW, you can also set its MinGW bin directory which should be at
C:Program Files (x86)CodeBlocksMinGWbin
Now when ever you run a command that uses a MinGW executable, the OS will know to look in the MinGW bin directory.
If you run your program and it complains that it can't find SDL2.dll, it means you did not set the path correctly.
3)Now go download the source for lesson 01. Extract the source somewhere. Open up a command window in the directory by holding shift and right clicking.
Now compile by entering this big old command (This command assumed you have SDL 2 extracted at C:mingw_dev_lib):
g++ 01_hello_SDL.cpp -IC:mingw_dev_libincludeSDL2 -LC:mingw_dev_liblib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o 01_hello_SDL
Having to manually punch in this compilation command gets very tedious very quickly. This is why I recommend using Make.
4) MingGW Make allows you to make build scripts that'll automate the compilation process.
#OBJS specifies which files to compile as part of the project OBJS = 01_hello_SDL.cpp #OBJ_NAME specifies the name of our exectuable OBJ_NAME = 01_hello_SDL #This is the target that compiles our executable all : $(OBJS) g++ $(OBJS) -IC:mingw_dev_libincludeSDL2 -LC:mingw_dev_liblib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o $(OBJ_NAME)
Here we have a basic Makefile. At the top we declare and set the 'OBJS' macro which specifies which files we're compiling. Then we set the 'OBJ_NAME' macro that specifies the name of our executable.
After setting these two macros, we have the 'all' target which compiles the program. It's followed by the dependencies which as you can see is the OBJS macro, because obviously you need the source files to compile the program.
After specifying the name of the target and its dependencies, the command to create the target is on the next line. The command to create the target must begin with a tab or Make will reject it.
As you would expect, the command to compile the program is largely the same as the command we would compile it off the command line. A key difference is that we have macros that we insert into the command which makes things like adding new files to the project must easier since you only have to change the macro as opposed to changing the whole command.
In future tutorials, we will be using more libraries. We should probably use more macros to make the process of adding them easier.
#OBJS specifies which files to compile as part of the project OBJS = 01_hello_SDL.cpp #CC specifies which compiler we're using CC = g++ #INCLUDE_PATHS specifies the additional include paths we'll need INCLUDE_PATHS = -IC:mingw_dev_libincludeSDL2 #LIBRARY_PATHS specifies the additional library paths we'll need LIBRARY_PATHS = -LC:mingw_dev_liblib #COMPILER_FLAGS specifies the additional compilation options we're using # -w suppresses all warnings # -Wl,-subsystem,windows gets rid of the console window COMPILER_FLAGS = -w -Wl,-subsystem,windows #LINKER_FLAGS specifies the libraries we're linking against LINKER_FLAGS = -lmingw32 -lSDL2main -lSDL2 #OBJ_NAME specifies the name of our exectuable OBJ_NAME = 01_hello_SDL #This is the target that compiles our executable all : $(OBJS) $(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)

Sd Clone

Now our compilation command is much more flexible.
Near the top we have the macros that define the files we're compiling and the compiler we're using.
Next we have the 'INCLUDE_PATHS' macro which specifies the additional directories we're getting header files from. As you can see, we're using the include directory from the SDL2 folder we extacted earlier. The 'LIBRARY_PATHS' sets the additional library file paths. Notice how there's a -I before every include directory and a -L before every library directory.
The 'COMPILER_FLAGS' macro are the additional options we use when compiling. In this case we're disabling all warnings and disabling the console window. The 'LINKER_FLAGS' macro specifies which libraries we're linking against. Here we're compiling against 32bit mingw, SDL2, and SDL2main. Notice how there's a -l flag before every library.
Finally at the bottom we have our target compiling using all of our macros. Thanks to macros we can very easily change the macros to add more files and libraries as we need them.
Save this Makefile code to a file named 'Makefile' (case sensitive with no file extension) or you can use the one I premade here. Open a command line in the directory with the source files and run the command mingw32-make.exe. Make will search for a file named 'Makefile' in the directory Make was called in and run the Makefile that will compile your code.
Now that you have SDL 2 compiling, it time to go onto part 2 of the tutorial.
Note: to run your application you'll have to add the SDL2 i686-w64-mingw32 bin directory to your PATH just like you added MinGW bin directory so Windows can find SDL2.dll. If you updated the PATH environment variable you'll need to close your command prompt and open a new one because the command prompt only reads updated environment variables when it opens.