Advertisement

SDL with VSCode on mac

Started by November 20, 2019 12:13 PM
5 comments, last by Neryss 5 years ago

Hey !

So i'm kinda new to mac OS, it's been a month I'm following class on openclasrooms. I'm used to compile with gcc and to code on VSCode. Here's the issue ;

I need to install and use SDL for my next chapter, but the tutorial is for Windows, the part for mac is only for XCode with a built in compiler. Since I'm new to mac I'm kinda scared to screw something up. I've downloaded SDL and double clicked it (while I was looking at the tutorial) and I was lost. So I checked other forums and asked on some of them, I also tried to install it with a brew in my terminal. I only saw people compiling it with a makefile but I didn't really understand how :/

That's why I ask here if someone could help me to understand how to use SLD and tell me if I installed it correctly.

Much thanks guys have a good day !

Here's a simple tutorial to setup SDL2 with GCC:
https://medium.com/@edkins.sarah/set-up-sdl2-on-your-mac-without-xcode-6b0c33b723f7

Basically, you just do 'brew install sdl2', and you should find SDL2 directories and libs in /usr/local/include and /usr/local/lib. You have to point to these directories in your makefile. Here's an example:


OBJS = $(wildcard */*.cpp)
CC = g++
INCLUDE_PATHS = -I/usr/local/include
LIBRARY_PATHS = -L/usr/local/lib
COMPILER_FLAGS = -std=c++11 -Wall -O2
LINKER_FLAGS = -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf
OBJ_NAME = exe_name

all:
	$(CC) -o $(OBJ_NAME) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(OBJS)

Hope this helps.

Advertisement

Hello !

Thanks for the quick answer, I guess I'll learn how to use the makefile properly since most people tend to tell me to use it. I'm gonna try tonight !

Thank you again you're the best !

Alright so quick update :

It definitely worked ! I did a simple printf to test if it works (while including SDL) !

Thank you so much for your help ! 

Just another quick question ; my makefile stand on one line while yours is several lines long, is it because I did something wrong ?

1 hour ago, Neryss said:

Alright so quick update :

It definitely worked ! I did a simple printf to test if it works (while including SDL) !

Thank you so much for your help ! 

Just another quick question ; my makefile stand on one line while yours is several lines long, is it because I did something wrong ?

Great! I'm not sure how your makefile looks right now but if you use variables they must be on a separate line. However, a makefile can be as simple as just 'g++ something.cpp', it's really nothing more than a fancy way to dress up a command line with arguments and flags.

You can easily test your makefile by running 'make' in the same directory. If the result is a working executable and no errors, you're good :)

25 minutes ago, Prototype said:

Great! I'm not sure how your makefile looks right now but if you use variables they must be on a separate line. However, a makefile can be as simple as just 'g++ something.cpp', it's really nothing more than a fancy way to dress up a command line with arguments and flags.

You can easily test your makefile by running 'make' in the same directory. If the result is a working executable and no errors, you're good :)

I tested it and it worked as it's meant to so I guess that's perfect ! I'll try to take a look at how I can write my makefile to be fancier but for now I need to figure out how to create my window on SDL2 since the tutorial I'm reading is for 1.2 xD

Anyway thank you so much for the help, I was stuck trying weird stuff since a couple of day :) 

This topic is closed to new replies.

Advertisement