Hello! I'm just starting out with makefiles, and I'm doing something using SDL (it's a cross-platform window manager). For this project, I want to incorporate a makefile into it, but I don't know what to do. The tutorials for SDL say to compile the program, use this command:

g++ sdltest.cpp -o sdltest.exe -lmingw32 -lSDLmain -lSDL -lSDL_mixer

However, I'm confused with how to put the libraries into the makefile. This is the current makefile:

CC = g++

sdlTest.exe: sdlTest.o
	$(CC) sdlTest.o -o sdlTest.exe

sdlTest.o: sdlTest.cpp
	$(CC) -c sdlTest.cpp

Where in that would the libraries go? Thanks in advance!

P.S. yes I am on a windows, but I'm using MinGW and make-for-windows.

6 Years
Discussion Span
Last Post by nezachem

Libraries are linked to the project, so they should go into a linkage recipe:

LIBS = -lmingw32 -lSDLmain -lSDL -lSDL_mixer
sdlTest.exe: sdlTest.o
    $(CC) sdlTest.o -o sdlTest.exe $(LIBS)

Notice that since they are 3rd-party, and not likely to change, they are not listed as dependencies.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.