LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-20-2006, 12:10 PM   #1
mansizerooster
LQ Newbie
 
Registered: Sep 2005
Posts: 12

Rep: Reputation: 0
SDL is installed, included and linked, but will not compile SDL code


Hi all,

I have been trying to get a nice fullscreen app with GLUT, but have had no luck as gamemode is not supported for my X. I have decided to try my luck with SDL, and so have installed it, have included it in my program with:

#include "SDL/SDL.h"

and have linked with my makefile as so (glut is still there so i don't need to strip it all out my code):

g++ -O0 -L/usr/X11R6/lib/ -lglut `sdl-config --cflags --libs` -lGL -lGLU src/Main.o -o demo

Now, this compiles and runs nicely before I add any sdl-specific code to my program, but as soon as I enter

SDL_Init(SDL_INIT_EVERYTHING);

I get this error:

Main.cpp.text+0x11da): undefined reference to `SDL_Init'

I don't understand what is going wrong, as I have installed, included it and linked it with my program. Could anybody please help point me towards where I am going wrong?

Thanks in advance.
 
Old 05-20-2006, 01:07 PM   #2
zackarya
Member
 
Registered: Jul 2003
Distribution: OpenSuse 10, Debian
Posts: 152

Rep: Reputation: 30
I believe you need to add -lSDL.

-lSDL flag tells gcc to link the libSDL.so shared library in with your program.

Hope that helps.

Zackarya
 
Old 05-21-2006, 06:48 AM   #3
mansizerooster
LQ Newbie
 
Registered: Sep 2005
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by zackarya
I believe you need to add -lSDL.

-lSDL flag tells gcc to link the libSDL.so shared library in with your program.

Hope that helps.

Zackarya

The `sdl-config --cflags --libs` is equivelant to that. I get the same error even when I actually do use -lSDL as well.
 
Old 05-21-2006, 11:22 PM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
yeh that looks like it should work.

run sdl-config by itself and see what paths its using and make sure they match up with what is actually on your system..
 
Old 05-21-2006, 11:33 PM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
Did you run ldconfig after you installed SDL?
 
Old 05-22-2006, 03:50 PM   #6
mansizerooster
LQ Newbie
 
Registered: Sep 2005
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Dark_Helmet
Did you run ldconfig after you installed SDL?

Yes, I have done that, but still no luck. I'm really stumped on this one.
 
Old 05-22-2006, 07:03 PM   #7
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,011

Rep: Reputation: 110Reputation: 110
Use #include "SDL.h", not #include "SDL/SDL.h". The SDL docs will confirm it.
For most anything, compile the separate .o files before linking because it helps with not having to recompile the whole file just because of a linker error.
Sample makefile that I use for one of my play programs.
Code:
CC = gcc
CFLAGS = `sdl-config --cflags` -g -Wall
all: maze
maze: maze.o
&tab;$(CC) `sdl-config --libs` -o maze maze.o
 
Old 05-23-2006, 12:37 AM   #8
mansizerooster
LQ Newbie
 
Registered: Sep 2005
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by tuxdev
Use #include "SDL.h", not #include "SDL/SDL.h". The SDL docs will confirm it.
For most anything, compile the separate .o files before linking because it helps with not having to recompile the whole file just because of a linker error.
Sample makefile that I use for one of my play programs.
Code:
CC = gcc
CFLAGS = `sdl-config --cflags` -g -Wall
all: maze
maze: maze.o
&tab;$(CC) `sdl-config --libs` -o maze maze.o

I tried this, but to no avail. Interestingly, the error I got may shed some light on the problem. When i change my #include to "SDL.h" instead of "SDL/SDL.h", I got this error:

src/Main.cpp:8:17: error: SDL.h: No such file or directory
src/Main.cpp: In function 'int main(int, char**)':
src/Main.cpp:237: error: 'SDL_INIT_EVERYTHING' was not declared in this scope
src/Main.cpp:237: error: 'SDL_Init' was not declared in this scope

As opposed to the error I got with "SDL/SDL.h",

src/Main.o: In function `main':
Main.cpp.text+0x11da): undefined reference to `SDL_Init'
collect2: ld returned 1 exit status

I think this shows that #include "SDL.h" works as it recognises SDL_INIT_EVERYTHING, just not the function it is used in.

Just an idea. And btw thanks everyone for trying to help me!
 
Old 05-27-2006, 09:52 AM   #9
mansizerooster
LQ Newbie
 
Registered: Sep 2005
Posts: 12

Original Poster
Rep: Reputation: 0
Hey everyone,

This is still a problem with me, and a really annoying one at that. Anyone have any ideas what could be wrong? Is there any information I could be disclosing that would help?
 
Old 05-30-2006, 07:13 PM   #10
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
Well, I can try to compile it on my machine. You'll need to post some code for me to work with though.

EDIT:
Also, where are the libs for SDL installed? Did you install with a package manager or from source? If from source and you installed to a non-standard location, what does ld.so.conf contain?

Do you use a Makefile? What's in it?

Last edited by Dark_Helmet; 05-30-2006 at 07:15 PM.
 
Old 05-31-2006, 04:18 AM   #11
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
I get this error:

Main.cpp.text+0x11da): undefined reference to `SDL_Init'
What is the prototype for your main function?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to compile a program with SDL RHLinuxGUY Programming 5 01-03-2006 12:12 AM
Sourcecompiling Problem...The sdl-config script installed by SDL could not be found. deepclutch Debian 1 12-15-2005 12:15 PM
Cannot compile SDL apps godice Linux - Software 2 05-22-2005 08:34 AM
Trying to program an SDL application but cannot find the SDL.h file:SuSE 9.2&KDevelop pujolasdf Linux - Newbie 4 03-13-2005 07:50 AM
What is a good IDE or such that will compile SDL? blufire Programming 3 03-07-2005 02:17 AM


All times are GMT -5. The time now is 10:41 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration