How to compile a program that uses SDL_image and SDL_ttf

I’m using Linux. I wrote a program that uses SDL_image and SDL_ttf
libraries. At this point I am trying to compile a source file - I’m not
linking yet, just compile. Here is my Makefile. It’s not complete yet:

CC=g++
CFLAGS=-O2 -W -Wall -pedantic
LIBS=-lSDL -lpthread

all: character.o ally.o enemy.o party.o allyparty.o enemyparty.o draw.o

character.o: character.cpp
$(CC) $(CFLAGS) -c character.cpp

ally.o: ally.cpp
$(CC) $(CFLAGS) -c ally.cpp character.o

enemy.o: enemy.cpp
$(CC) $(CFLAGS) -c enemy.cpp character.o

party.o: character.o party.cpp
$(CC) $(CFLAGS) -c party.cpp character.o

allyparty.o: party.o ally.o allyparty.cpp
$(CC) $(CFLAGS) -c allyparty.cpp party.o ally.o

enemyparty.o: party.o enemy.o enemyparty.cpp
$(CC) $(CFLAGS) -c enemyparty.cpp party.o enemy.o

draw.o: draw.cpp allyparty.o enemyparty.o
$(CC) $(CFLAGS) -c draw.cpp enemyparty.o allyparty.o

clean:
rm *.o
rm *~

All targets compile fine, except draw.o. That gives me errors:

michael at camille OurRPG $ make
g++ -O2 -W -Wall -pedantic -c draw.cpp enemyparty.o allyparty.o
In file included from draw.cpp:1:
draw.h:4:23: error: sdl_image.h: No such file or directory
draw.h:5:21: error: sdl_ttf.h: No such file or directory
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g+±v4/memory: In function
’std::pair<_Tp*, int> std::__get_temporary_buffer(ptrdiff_t, _Tp*)’:
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g+±v4/memory:83: error:
‘nothrow’ was not declared in this scope
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g+±v4/memory: In function
’void std::return_temporary_buffer(_Tp*)’:
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g+±v4/memory:123: error:
‘nothrow’ was not declared in this scope
party.h: At global scope:
party.h:7: warning: ‘class Party’ has virtual functions but non-virtual
destructor
allyparty.h:9: warning: ‘class AllyParty’ has virtual functions but
non-virtual destructor
enemyparty.h:8: warning: ‘class EnemyParty’ has virtual functions but
non-virtual destructor
draw.h:29: error: ISO C++ forbids declaration of ‘TTF_Font’ with no type
draw.h:29: error: expected ‘;’ before ‘*’ token
draw.cpp: In member function ‘void Draw::Init()’:
draw.cpp:28: error: ‘TTF_Init’ was not declared in this scope
draw.cpp:34: error: ‘font’ was not declared in this scope
draw.cpp:34: error: ‘TTF_OpenFont’ was not declared in this scope
draw.cpp:36: warning: missing initializer for member 'SDL_Color::unused’
draw.cpp:37: warning: missing initializer for member 'SDL_Color::unused’
draw.cpp:44: error: ‘sprintf_s’ was not declared in this scope
draw.cpp:46: error: ‘TTF_RenderText_Shaded’ was not declared in this
scope
draw.cpp: In member function ‘void Draw::draw(int)’:
draw.cpp:102: error: ‘IMG_Load’ was not declared in this scope
draw.cpp: At global scope:
draw.cpp:84: warning: unused parameter 'state’
make: *** [draw.o] Error 1

Here are the #include lines from draw.h:

#include <SDL/SDL.h>
#include <sdl_image.h>
#include <sdl_ttf.h>

I ran configure, make, and make install on the SDL_image and SDL_ttf
packages, so they’re in /usr/local/lib and /usr/local/include. What do
I need to set to get this thing to compile?

Linux is case-sensitive. I think your problem is that you’re asking for
sdl_* when you mean SDL_*.

Jonny DOn Sat, Mar 7, 2009 at 10:01 AM, Michael Sullivan wrote:

I’m using Linux. I wrote a program that uses SDL_image and SDL_ttf
libraries. At this point I am trying to compile a source file - I’m not
linking yet, just compile. Here is my Makefile. It’s not complete yet:

CC=g++
CFLAGS=-O2 -W -Wall -pedantic
LIBS=-lSDL -lpthread

all: character.o ally.o enemy.o party.o allyparty.o enemyparty.o draw.o

character.o: character.cpp
$(CC) $(CFLAGS) -c character.cpp

ally.o: ally.cpp
$(CC) $(CFLAGS) -c ally.cpp character.o

enemy.o: enemy.cpp
$(CC) $(CFLAGS) -c enemy.cpp character.o

party.o: character.o party.cpp
$(CC) $(CFLAGS) -c party.cpp character.o

allyparty.o: party.o ally.o allyparty.cpp
$(CC) $(CFLAGS) -c allyparty.cpp party.o ally.o

enemyparty.o: party.o enemy.o enemyparty.cpp
$(CC) $(CFLAGS) -c enemyparty.cpp party.o enemy.o

draw.o: draw.cpp allyparty.o enemyparty.o
$(CC) $(CFLAGS) -c draw.cpp enemyparty.o allyparty.o

clean:
rm *.o
rm *~

All targets compile fine, except draw.o. That gives me errors:

michael at camille OurRPG $ make
g++ -O2 -W -Wall -pedantic -c draw.cpp enemyparty.o allyparty.o
In file included from draw.cpp:1:
draw.h:4:23: error: sdl_image.h: No such file or directory
draw.h:5:21: error: sdl_ttf.h: No such file or directory
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g+±v4/memory: In function
’std::pair<_Tp*, int> std::__get_temporary_buffer(ptrdiff_t, _Tp*)’:
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g+±v4/memory:83: error:
‘nothrow’ was not declared in this scope
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g+±v4/memory: In function
’void std::return_temporary_buffer(_Tp*)’:
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g+±v4/memory:123: error:
‘nothrow’ was not declared in this scope
party.h: At global scope:
party.h:7: warning: ‘class Party’ has virtual functions but non-virtual
destructor
allyparty.h:9: warning: ‘class AllyParty’ has virtual functions but
non-virtual destructor
enemyparty.h:8: warning: ‘class EnemyParty’ has virtual functions but
non-virtual destructor
draw.h:29: error: ISO C++ forbids declaration of ‘TTF_Font’ with no type
draw.h:29: error: expected ‘;’ before ‘*’ token
draw.cpp: In member function ‘void Draw::Init()’:
draw.cpp:28: error: ‘TTF_Init’ was not declared in this scope
draw.cpp:34: error: ‘font’ was not declared in this scope
draw.cpp:34: error: ‘TTF_OpenFont’ was not declared in this scope
draw.cpp:36: warning: missing initializer for member 'SDL_Color::unused’
draw.cpp:37: warning: missing initializer for member 'SDL_Color::unused’
draw.cpp:44: error: ‘sprintf_s’ was not declared in this scope
draw.cpp:46: error: ‘TTF_RenderText_Shaded’ was not declared in this
scope
draw.cpp: In member function ‘void Draw::draw(int)’:
draw.cpp:102: error: ‘IMG_Load’ was not declared in this scope
draw.cpp: At global scope:
draw.cpp:84: warning: unused parameter 'state’
make: *** [draw.o] Error 1

Here are the #include lines from draw.h:

#include <SDL/SDL.h>
#include <sdl_image.h>
#include <sdl_ttf.h>

I ran configure, make, and make install on the SDL_image and SDL_ttf
packages, so they’re in /usr/local/lib and /usr/local/include. What do
I need to set to get this thing to compile?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Linux is case-sensitive. I think your problem is that you’re asking
for sdl_* when you mean SDL_*.

Jonny D

    I'm using Linux.  I wrote a program that uses SDL_image and
    SDL_ttf
    libraries.  At this point I am trying to compile a source file
    - I'm not
    linking yet, just compile.  Here is my Makefile.  It's not
    complete yet:
    
    
    CC=g++
    CFLAGS=-O2 -W -Wall -pedantic
    LIBS=-lSDL -lpthread
    
    all:  character.o ally.o enemy.o party.o allyparty.o
    enemyparty.o draw.o
    
    
    character.o: character.cpp
           $(CC) $(CFLAGS) -c character.cpp
    
    
    ally.o: ally.cpp
           $(CC) $(CFLAGS) -c ally.cpp character.o
    
    enemy.o:  enemy.cpp
           $(CC) $(CFLAGS) -c enemy.cpp character.o
    
    party.o:  character.o party.cpp
           $(CC) $(CFLAGS) -c party.cpp character.o
    
    allyparty.o:  party.o ally.o allyparty.cpp
           $(CC) $(CFLAGS) -c allyparty.cpp party.o ally.o
    
    enemyparty.o:  party.o enemy.o enemyparty.cpp
           $(CC) $(CFLAGS) -c enemyparty.cpp party.o enemy.o
    
    draw.o:  draw.cpp allyparty.o enemyparty.o
           $(CC) $(CFLAGS) -c draw.cpp enemyparty.o allyparty.o
    
    
    
    
    clean:
           rm *.o
           rm *~
    
    All targets compile fine, except draw.o.  That gives me
    errors:
    
    michael at camille OurRPG $ make
    g++ -O2 -W -Wall -pedantic -c draw.cpp enemyparty.o
    allyparty.o
    In file included from draw.cpp:1:
    draw.h:4:23: error: sdl_image.h: No such file or directory
    draw.h:5:21: error: sdl_ttf.h: No such file or directory
    /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/memory: In
    function
    'std::pair<_Tp*, int> std::__get_temporary_buffer(ptrdiff_t,
    _Tp*)':
    /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/memory:83:
    error:
    'nothrow' was not declared in this scope
    /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/memory: In
    function
    'void std::return_temporary_buffer(_Tp*)':
    /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g
    ++-v4/memory:123: error:
    'nothrow' was not declared in this scope
    party.h: At global scope:
    party.h:7: warning: 'class Party' has virtual functions but
    non-virtual
    destructor
    allyparty.h:9: warning: 'class AllyParty' has virtual
    functions but
    non-virtual destructor
    enemyparty.h:8: warning: 'class EnemyParty' has virtual
    functions but
    non-virtual destructor
    draw.h:29: error: ISO C++ forbids declaration of 'TTF_Font'
    with no type
    draw.h:29: error: expected ';' before '*' token
    draw.cpp: In member function 'void Draw::Init()':
    draw.cpp:28: error: 'TTF_Init' was not declared in this scope
    draw.cpp:34: error: 'font' was not declared in this scope
    draw.cpp:34: error: 'TTF_OpenFont' was not declared in this
    scope
    draw.cpp:36: warning: missing initializer for member
    'SDL_Color::unused'
    draw.cpp:37: warning: missing initializer for member
    'SDL_Color::unused'
    draw.cpp:44: error: 'sprintf_s' was not declared in this scope
    draw.cpp:46: error: 'TTF_RenderText_Shaded' was not declared
    in this
    scope
    draw.cpp: In member function 'void Draw::draw(int)':
    draw.cpp:102: error: 'IMG_Load' was not declared in this scope
    draw.cpp: At global scope:
    draw.cpp:84: warning: unused parameter 'state'
    make: *** [draw.o] Error 1
    
    Here are the #include lines from draw.h:
    
    #include <SDL/SDL.h>
    #include <sdl_image.h>
    #include <sdl_ttf.h>
    
    
    I ran configure, make, and make install on the SDL_image and
    SDL_ttf
    packages, so they're in /usr/local/lib
    and /usr/local/include.  What do
    I need to set to get this thing to compile?

I added sdl-config --cflags
to my CFLAGS variable and those errors are gone now. Now the only
error is for nothrow

michael at camille OurRPG $ make
g++ -O2 -W -Wall -pedantic sdl-config --cflags -c draw.cpp
enemyparty.o allyparty.o
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g+±v4/memory: In function
’std::pair<_Tp*, int> std::__get_temporary_buffer(ptrdiff_t, _Tp*)’:
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g+±v4/memory:83: error:
‘nothrow’ was not declared in this scope
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g+±v4/memory: In function
’void std::return_temporary_buffer(_Tp*)’:
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g+±v4/memory:123: error:
‘nothrow’ was not declared in this scope
party.h: At global scope:
party.h:7: warning: ‘class Party’ has virtual functions but non-virtual
destructor
allyparty.h:9: warning: ‘class AllyParty’ has virtual functions but
non-virtual destructor
enemyparty.h:8: warning: ‘class EnemyParty’ has virtual functions but
non-virtual destructor
draw.cpp: In member function ‘void Draw::Init()’:
draw.cpp:36: warning: missing initializer for member 'SDL_Color::unused’
draw.cpp:37: warning: missing initializer for member 'SDL_Color::unused’
draw.cpp: At global scope:
draw.cpp:84: warning: unused parameter 'state’
make: *** [draw.o] Error 1

but I don’t think that’s an SDL problem. I have written to the mailing
list for my distrobution asking for instructions of how I should deal
with this problem…On Sat, 2009-03-07 at 10:54 -0500, Jonathan Dearborn wrote:

On Sat, Mar 7, 2009 at 10:01 AM, Michael Sullivan <@Michael_Sullivan> wrote: