Makefile

I’m playing around with linux for the first time and I’m trying to
create a Makefile for a very simple SDL program that does nothing but
initialize graphics and does the event loop until escape is pressed. It
has one file, main.cpp. This is what my Makefile looks like:----------------------------------------------
test: main.cpp
gcc -c main.cpp
gcc main.o -lSDL -o test

When I run make on this, it shows me all kinds of stuff, starting with


[micah at mandrake9 test]$ make
gcc -c main.cpp
gcc main.o -lSDL -o test
main.o(.eh_frame+0x11): undefined reference to __gxx_personality_v0' /usr//bin/../lib/gcc-lib/i586-mandrake-linux-gnu/3.2/../../../libSDL.a(SDL_x11video.lo): In functionX11_Available’:
SDL_x11video.lo(.text+0x1d): undefined reference to XOpenDisplay' SDL_x11video.lo(.text+0x2f): undefined reference toXCloseDisplay’
/usr//bin/…/lib/gcc-lib/i586-mandrake-linux-gnu/3.2/…/…/…/libSDL.a(SDL_x11video.lo): In function create_aux_windows': SDL_x11video.lo(.text+0x453): undefined reference toXDestroyWindow’
SDL_x11video.lo(.text+0x4ff): undefined reference to `XCreateWindow’

and the errors just keep coming. I have a feeling this is either a
messed up installation of SDL-devel (which I don’t think it is, because
I used the RPM), or my Makefile is somehow messed up. Can anyone help?
Thanks.

  • Micah

Try using sdl-config --cflags when compiling and sdl-config --libs when
linking.On Monday 06 January 2003 03:40 pm, you wrote:

I’m playing around with linux for the first time and I’m trying to
create a Makefile for a very simple SDL program that does nothing but
initialize graphics and does the event loop until escape is pressed. It
has one file, main.cpp. This is what my Makefile looks like:


test: main.cpp
gcc -c main.cpp
gcc main.o -lSDL -o test

When I run make on this, it shows me all kinds of stuff, starting with


[micah at mandrake9 test]$ make
gcc -c main.cpp
gcc main.o -lSDL -o test
main.o(.eh_frame+0x11): undefined reference to __gxx_personality_v0' /usr//bin/../lib/gcc-lib/i586-mandrake-linux-gnu/3.2/../../../libSDL.a(SDL_ x11video.lo): In functionX11_Available’: SDL_x11video.lo(.text+0x1d):
undefined reference to XOpenDisplay' SDL_x11video.lo(.text+0x2f): undefined reference toXCloseDisplay’
/usr//bin/…/lib/gcc-lib/i586-mandrake-linux-gnu/3.2/…/…/…/libSDL.a(SDL_
x11video.lo): In function create_aux_windows': SDL_x11video.lo(.text+0x453): undefined reference toXDestroyWindow’
SDL_x11video.lo(.text+0x4ff): undefined reference to `XCreateWindow’

and the errors just keep coming. I have a feeling this is either a
messed up installation of SDL-devel (which I don’t think it is, because
I used the RPM), or my Makefile is somehow messed up. Can anyone help?
Thanks.

  • Micah

SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Try using sdl-config --cflags when compiling and sdl-config --libs when
linking.

You’ll also need to use g++ instead of gcc, since you’re compiling C++.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Micah Lee wrote:


test: main.cpp
gcc -c main.cpp
gcc main.o -lSDL -o test

When I run make on this, it shows me all kinds of stuff, starting with…

I’m not sure if this is the solution to your problem, but IMO you should
use “sdl-config” script when compiling/linking. Something like:

gcc 'sdl-config --cflags' -c main.cpp
gcc main.o 'sdl-config --libs' -o test

Notice the ’ are backticks, not ’ quotes.
But as I said, this is probably unrelevant to your problem.–
Mika Halttunen
@Mika_Halttunen

Now my Makefile looks like this:-----------------------------------------------
test: main.cpp
g++ sdl-config --cflags -c main.cpp
g++ main.o sdl-config --libs -o test

And it still gives me errors:


[micah at mandrake9 test]$ make
g++ sdl-config --cflags -c main.cpp
g++ main.o sdl-config --libs -o test
/usr/lib/libSDL.a(SDL_x11video.lo): In function X11_Available': SDL_x11video.lo(.text+0x1d): undefined reference toXOpenDisplay’
SDL_x11video.lo(.text+0x2f): undefined reference to XCloseDisplay' /usr/lib/libSDL.a(SDL_x11video.lo): In functioncreate_aux_windows’:
SDL_x11video.lo(.text+0x453): undefined reference to XDestroyWindow' SDL_x11video.lo(.text+0x4ff): undefined reference toXCreateWindow’
SDL_x11video.lo(.text+0x528): undefined reference to XSelectInput' SDL_x11video.lo(.text+0x583): undefined reference toXInternAtom’
SDL_x11video.lo(.text+0x5da): undefined reference to XSendEvent' SDL_x11video.lo(.text+0x5ff): undefined reference toXGetWMHints’
SDL_x11video.lo(.text+0x61b): undefined reference to XGetWMName' SDL_x11video.lo(.text+0x638): undefined reference toXGetWMIconName’
SDL_x11video.lo(.text+0x64e): undefined reference to XDestroyWindow' SDL_x11video.lo(.text+0x6a0): undefined reference toXCreateWindow’
SDL_x11video.lo(.text+0x6b7): undefined reference to `XAllocWMHints’

Of course, using sdl-config is definitely good advice. I just realized
that all of the errors have to do with video mode in X. If I comment
out everything except SDL_Init(0) and SDL_Quit() and stick an
SDL_Delay(1000) in the middle and try making it, it still gives me all
the same errors, if that helps.

On Tue, 2003-01-07 at 15:28, Mika Halttunen wrote:

Micah Lee wrote:


test: main.cpp
gcc -c main.cpp
gcc main.o -lSDL -o test

When I run make on this, it shows me all kinds of stuff, starting with…

I’m not sure if this is the solution to your problem, but IMO you should
use “sdl-config” script when compiling/linking. Something like:

gcc ‘sdl-config --cflags’ -c main.cpp
gcc main.o ‘sdl-config --libs’ -o test

Notice the ’ are backticks, not ’ quotes.
But as I said, this is probably unrelevant to your problem.


Mika Halttunen
lsoft at mbnet.fi


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I’ve also gotten those same errors after upgrading to the latest
SDL-devel. I got Mandrake 8.1. It looks like you got Mandrake 9.0.
Perhaps it’s a Mandrake thing. Try adding the -lGL option, like this:

test: main.cpp
g++ sdl-config --cflags -c main.cpp
g++ main.o -o test sdl-config --libs -L/usr/X11R6/lib -lGL

Please let me know how that goes. I’m curious.

-MarkOn 7 Jan 2003, Micah Lee wrote:

Now my Makefile looks like this:


test: main.cpp
g++ sdl-config --cflags -c main.cpp
g++ main.o sdl-config --libs -o test

And it still gives me errors:


[micah at mandrake9 test]$ make
g++ sdl-config --cflags -c main.cpp
g++ main.o sdl-config --libs -o test
/usr/lib/libSDL.a(SDL_x11video.lo): In function X11_Available': SDL_x11video.lo(.text+0x1d): undefined reference toXOpenDisplay’
SDL_x11video.lo(.text+0x2f): undefined reference to XCloseDisplay' /usr/lib/libSDL.a(SDL_x11video.lo): In functioncreate_aux_windows’:
SDL_x11video.lo(.text+0x453): undefined reference to XDestroyWindow' SDL_x11video.lo(.text+0x4ff): undefined reference toXCreateWindow’
SDL_x11video.lo(.text+0x528): undefined reference to XSelectInput' SDL_x11video.lo(.text+0x583): undefined reference toXInternAtom’
SDL_x11video.lo(.text+0x5da): undefined reference to XSendEvent' SDL_x11video.lo(.text+0x5ff): undefined reference toXGetWMHints’
SDL_x11video.lo(.text+0x61b): undefined reference to XGetWMName' SDL_x11video.lo(.text+0x638): undefined reference toXGetWMIconName’
SDL_x11video.lo(.text+0x64e): undefined reference to XDestroyWindow' SDL_x11video.lo(.text+0x6a0): undefined reference toXCreateWindow’
SDL_x11video.lo(.text+0x6b7): undefined reference to `XAllocWMHints’

Of course, using sdl-config is definitely good advice. I just realized
that all of the errors have to do with video mode in X. If I comment
out everything except SDL_Init(0) and SDL_Quit() and stick an
SDL_Delay(1000) in the middle and try making it, it still gives me all
the same errors, if that helps.

On Tue, 2003-01-07 at 15:28, Mika Halttunen wrote:

Micah Lee wrote:


test: main.cpp
gcc -c main.cpp
gcc main.o -lSDL -o test

When I run make on this, it shows me all kinds of stuff, starting with…

I’m not sure if this is the solution to your problem, but IMO you should
use “sdl-config” script when compiling/linking. Something like:

gcc 'sdl-config --cflags' -c main.cpp
gcc main.o 'sdl-config --libs' -o test

Notice the ’ are backticks, not ’ quotes.
But as I said, this is probably unrelevant to your problem.


Mika Halttunen
lsoft at mbnet.fi


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Mark K. Kim
http://www.cbreak.org/
PGP key available upon request.

Yes, I do have Mandrake 9 and whoa… it works. Thanks! So -lGL is the
OpenGL library, I take it? That’s good to know. Thanks a lot.

  • Micah, the new Linux developer; woohoo!On Wed, 2003-01-08 at 03:32, Mark K. Kim wrote:

I’ve also gotten those same errors after upgrading to the latest
SDL-devel. I got Mandrake 8.1. It looks like you got Mandrake 9.0.
Perhaps it’s a Mandrake thing. Try adding the -lGL option, like this:

test: main.cpp
g++ sdl-config --cflags -c main.cpp
g++ main.o -o test sdl-config --libs -L/usr/X11R6/lib -lGL

Please let me know how that goes. I’m curious.

-Mark

On 7 Jan 2003, Micah Lee wrote:

Now my Makefile looks like this:


test: main.cpp
g++ sdl-config --cflags -c main.cpp
g++ main.o sdl-config --libs -o test

And it still gives me errors:


[micah at mandrake9 test]$ make
g++ sdl-config --cflags -c main.cpp
g++ main.o sdl-config --libs -o test
/usr/lib/libSDL.a(SDL_x11video.lo): In function X11_Available': SDL_x11video.lo(.text+0x1d): undefined reference toXOpenDisplay’
SDL_x11video.lo(.text+0x2f): undefined reference to XCloseDisplay' /usr/lib/libSDL.a(SDL_x11video.lo): In functioncreate_aux_windows’:
SDL_x11video.lo(.text+0x453): undefined reference to XDestroyWindow' SDL_x11video.lo(.text+0x4ff): undefined reference toXCreateWindow’
SDL_x11video.lo(.text+0x528): undefined reference to XSelectInput' SDL_x11video.lo(.text+0x583): undefined reference toXInternAtom’
SDL_x11video.lo(.text+0x5da): undefined reference to XSendEvent' SDL_x11video.lo(.text+0x5ff): undefined reference toXGetWMHints’
SDL_x11video.lo(.text+0x61b): undefined reference to XGetWMName' SDL_x11video.lo(.text+0x638): undefined reference toXGetWMIconName’
SDL_x11video.lo(.text+0x64e): undefined reference to XDestroyWindow' SDL_x11video.lo(.text+0x6a0): undefined reference toXCreateWindow’
SDL_x11video.lo(.text+0x6b7): undefined reference to `XAllocWMHints’

Of course, using sdl-config is definitely good advice. I just realized
that all of the errors have to do with video mode in X. If I comment
out everything except SDL_Init(0) and SDL_Quit() and stick an
SDL_Delay(1000) in the middle and try making it, it still gives me all
the same errors, if that helps.

On Tue, 2003-01-07 at 15:28, Mika Halttunen wrote:

Micah Lee wrote:


test: main.cpp
gcc -c main.cpp
gcc main.o -lSDL -o test

When I run make on this, it shows me all kinds of stuff, starting with…

I’m not sure if this is the solution to your problem, but IMO you should
use “sdl-config” script when compiling/linking. Something like:

gcc 'sdl-config --cflags' -c main.cpp
gcc main.o 'sdl-config --libs' -o test

Notice the ’ are backticks, not ’ quotes.
But as I said, this is probably unrelevant to your problem.


Mika Halttunen
lsoft at mbnet.fi


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Mark K. Kim
http://www.cbreak.org/
PGP key available upon request.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Also, make sure you have the XFree86-devel package installed. I know it
sounds crazy, but that’s what it looks like to me.

Mark K. Kim wrote:>I’ve also gotten those same errors after upgrading to the latest

SDL-devel. I got Mandrake 8.1. It looks like you got Mandrake 9.0.
Perhaps it’s a Mandrake thing. Try adding the -lGL option, like this:

test: main.cpp
g++ sdl-config --cflags -c main.cpp
g++ main.o -o test sdl-config --libs -L/usr/X11R6/lib -lGL

Please let me know how that goes. I’m curious.

-Mark

On 7 Jan 2003, Micah Lee wrote:

Now my Makefile looks like this:


test: main.cpp
g++ sdl-config --cflags -c main.cpp
g++ main.o sdl-config --libs -o test

And it still gives me errors:


[micah at mandrake9 test]$ make
g++ sdl-config --cflags -c main.cpp
g++ main.o sdl-config --libs -o test
/usr/lib/libSDL.a(SDL_x11video.lo): In function X11_Available': SDL_x11video.lo(.text+0x1d): undefined reference toXOpenDisplay’
SDL_x11video.lo(.text+0x2f): undefined reference to XCloseDisplay' /usr/lib/libSDL.a(SDL_x11video.lo): In functioncreate_aux_windows’:
SDL_x11video.lo(.text+0x453): undefined reference to XDestroyWindow' SDL_x11video.lo(.text+0x4ff): undefined reference toXCreateWindow’
SDL_x11video.lo(.text+0x528): undefined reference to XSelectInput' SDL_x11video.lo(.text+0x583): undefined reference toXInternAtom’
SDL_x11video.lo(.text+0x5da): undefined reference to XSendEvent' SDL_x11video.lo(.text+0x5ff): undefined reference toXGetWMHints’
SDL_x11video.lo(.text+0x61b): undefined reference to XGetWMName' SDL_x11video.lo(.text+0x638): undefined reference toXGetWMIconName’
SDL_x11video.lo(.text+0x64e): undefined reference to XDestroyWindow' SDL_x11video.lo(.text+0x6a0): undefined reference toXCreateWindow’
SDL_x11video.lo(.text+0x6b7): undefined reference to `XAllocWMHints’

Of course, using sdl-config is definitely good advice. I just realized
that all of the errors have to do with video mode in X. If I comment
out everything except SDL_Init(0) and SDL_Quit() and stick an
SDL_Delay(1000) in the middle and try making it, it still gives me all
the same errors, if that helps.

On Tue, 2003-01-07 at 15:28, Mika Halttunen wrote:

Micah Lee wrote:


test: main.cpp
gcc -c main.cpp
gcc main.o -lSDL -o test

When I run make on this, it shows me all kinds of stuff, starting with…

I’m not sure if this is the solution to your problem, but IMO you should
use “sdl-config” script when compiling/linking. Something like:

gcc ‘sdl-config --cflags’ -c main.cpp
gcc main.o ‘sdl-config --libs’ -o test

Notice the ’ are backticks, not ’ quotes.
But as I said, this is probably unrelevant to your problem.


Mika Halttunen
lsoft at mbnet.fi


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl