Chozla
Posts: 4
Joined: Sat Feb 27, 2016 2:46 am

Gcc, SDL building using a makefile

Wed Mar 09, 2016 1:35 am

I am trying to build a project with make (gcc on Raspbian)

Here is the makefile (I removed some unnecessary parts):

Code: Select all

objects = 3d.o Affichage.o   [...]
cflags = -I/usr/local/include/SDL2 -L/usr/local/lib -lSDL2
poly : %(objects)
        gcc $(cflags) $(objects) -o poly

($objects) : types.h
[...]
When running Make, I get:

Code: Select all

cc  -c -o Affichage.o Affichage.c
fatal error: SDL.h: No such file or directory
 #include <SDL.h>
I checked the folders, everything seems ok. SDL.h is indeed in /usr/local/include/SDL2. I tried to remove options one by one in cflags, no luck...

What am I missing?

User avatar
PeterO
Posts: 5951
Joined: Sun Jul 22, 2012 4:14 pm

Re: Gcc, SDL building using a makefile

Wed Mar 09, 2016 7:20 am

The -I flag needs to be supplied to gcc when it does the compile stage (source files (.c) to object files (.o)) . It looks like your makefile only adds it to the link stage (object files + libraries to executable file).
The -L and -l flags need to be supplied to the link stage.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Chozla
Posts: 4
Joined: Sat Feb 27, 2016 2:46 am

Re: Gcc, SDL building using a makefile

Thu Mar 10, 2016 1:46 am

Ok, I am trying it, I also got an answer from someone else. I changed the first lines with this:

Code: Select all

CC:=gcc
CFLAGS:=-I/usr/local/include/SDL2
LIBS:=-lSDL2
LDFLAGS:=-L/usr/local/lib $(LIBS)
objects:=3d.o Affichage.o
poly: $(objects)
    $(CC) $^ -o $@ $(LDFLAGS)
It seems to work right now.

Thanks!

Return to “Graphics programming”