ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
[unholy@localhost example1]$ gcc example1.c -o example -lSDL -lpthread
example1.c:10:17: SDL.h: No such file or directory
example1.c:13: error: syntax error before '*' token
example1.c: In function `setpixel':
example1.c:15: error: `Uint8' undeclared (first use in this function)
example1.c:15: error: (Each undeclared identifier is reported only once
example1.c:15: error: for each function it appears in.)
example1.c:15: error: `ubuff8' undeclared (first use in this function)
example1.c:16: error: `Uint16' undeclared (first use in this function)
example1.c:16: error: `ubuff16' undeclared (first use in this function)
example1.c:17: error: `Uint32' undeclared (first use in this function)
example1.c:17: error: `ubuff32' undeclared (first use in this function)
example1.c:18: error: syntax error before "color"
example1.c:22: error: `screen' undeclared (first use in this function)
example1.c:28: error: `color' undeclared (first use in this function)
example1.c:28: error: `r' undeclared (first use in this function)
example1.c:28: error: `g' undeclared (first use in this function)
example1.c:28: error: `b' undeclared (first use in this function)
example1.c:34: error: syntax error before ')' token
example1.c:35: error: `y' undeclared (first use in this function)
example1.c:35: error: `x' undeclared (first use in this function)
example1.c:36: error: syntax error before "color"
example1.c:40: error: syntax error before ')' token
example1.c:42: error: syntax error before ')' token
example1.c:43: error: syntax error before "color"
example1.c:47: error: syntax error before ')' token
example1.c:51: error: `SDL_BYTEORDER' undeclared (first use in this function)
example1.c:51: error: `SDL_LIL_ENDIAN' undeclared (first use in this function)
example1.c:67: error: syntax error before ')' token
example1.c:69: error: syntax error before ')' token
example1.c: At top level:
example1.c:84: error: syntax error before '*' token
example1.c: In function `DrawPicture':
example1.c:90: error: `screen' undeclared (first use in this function)
example1.c: In function `main':
example1.c:103: error: `SDL_Surface' undeclared (first use in this function)
example1.c:103: error: `screen' undeclared (first use in this function)
example1.c:104: error: `SDL_Event' undeclared (first use in this function)
example1.c:104: error: syntax error before "event"
example1.c:110: error: `SDL_INIT_VIDEO' undeclared (first use in this function)
example1.c:117: error: `SDL_Quit' undeclared (first use in this function)
example1.c:120: error: `SDL_SWSURFACE' undeclared (first use in this function)
example1.c:120: error: `SDL_ANYFORMAT' undeclared (first use in this function)
example1.c:136: error: `event' undeclared (first use in this function)
example1.c:139: error: `SDL_QUIT' undeclared (first use in this function)
example1.c:143: error: `SDL_KEYDOWN' undeclared (first use in this function)
[unholy@localhost example1]$ gcc -g -Wall `sdl-config --cflags` `sdl-config --libs` -o example1 example1.c
example1.c: In function `DrawPicture':
example1.c:86: warning: unused variable `r'
example1.c:86: warning: unused variable `g'
example1.c:86: warning: unused variable `b'
example1.c: In function `main':
example1.c:128: warning: unsigned int format, pointer arg (arg 2)
/home/unholy/tmp/ccCOzzDc.o(.text+0x38): In function `setpixel':
/home/unholy/programming/example1/example1.c:23: undefined reference to `SDL_LockSurface'
/home/unholy/tmp/ccCOzzDc.o(.text+0x6a):/home/unholy/programming/example1/example1.c:28: undefined reference to `SDL_MapRGB'
/home/unholy/tmp/ccCOzzDc.o(.text+0x1f6):/home/unholy/programming/example1/example1.c:79: undefined reference to `SDL_UnlockSurface'
/home/unholy/tmp/ccCOzzDc.o(.text+0x27f): In function `DrawPicture':
/home/unholy/programming/example1/example1.c:96: undefined reference to `SDL_Flip'
/home/unholy/tmp/ccCOzzDc.o(.text+0x2a5): In function `main':
/home/unholy/programming/example1/example1.c:110: undefined reference to `SDL_Init'
/home/unholy/tmp/ccCOzzDc.o(.text+0x2b7):/home/unholy/programming/example1/example1.c:111: undefined reference to `SDL_GetError'
/home/unholy/tmp/ccCOzzDc.o(.text+0x2e2):/home/unholy/programming/example1/example1.c:117: undefined reference to `SDL_Quit'
/home/unholy/tmp/ccCOzzDc.o(.text+0x300):/home/unholy/programming/example1/example1.c:120: undefined reference to `SDL_SetVideoMode'
/home/unholy/tmp/ccCOzzDc.o(.text+0x317):/home/unholy/programming/example1/example1.c:122: undefined reference to `SDL_GetError'
/home/unholy/tmp/ccCOzzDc.o(.text+0x3ba):/home/unholy/programming/example1/example1.c:136: undefined reference to `SDL_PollEvent'
collect2: ld returned 1 exit status
[unholy@localhost example1]$ gcc example1.c -o example1 -lSDL -lpthread
/usr//bin/../lib/gcc-lib/i586-mandrake-linux-gnu/3.3.1/../../../libSDL.a(SDL_x11video.lo)(.text+0x1d): In function `X11_Available':
: undefined reference to `XOpenDisplay'
/usr//bin/../lib/gcc-lib/i586-mandrake-linux-gnu/3.3.1/../../../libSDL.a(SDL_x11video.lo)(.text+0x2f): In function `X11_Available':
: undefined reference to `XCloseDisplay'
/usr//bin/../lib/gcc-lib/i586-mandrake-linux-gnu/3.3.1/../../../libSDL.a(SDL_x11video.lo)(.text+0x453): In function `create_aux_windows':
: undefined reference to `XDestroyWindow'
/usr//bin/../lib/gcc-lib/i586-mandrake-linux-gnu/3.3.1/../../../libSDL.a(SDL_x11video.lo)(.text+0x4ff): In function `create_aux_windows':
: undefined reference to `XCreateWindow'
/usr//bin/../lib/gcc-lib/i586-mandrake-linux-gnu/3.3.1/../../../libSDL.a(SDL_x11video.lo)(.text+0x528): In function `create_aux_windows':
: undefined reference to `XSelectInput'
//lots more
Would you mind trying to compile the code I posted earlies to see if it compiles on your machine?
The errors you posted refer to libSDL.a. Seems the linker cannot find the dynamic libs (libSDL.so). Though I guess it should be very well posible to link SDL statically, it is not the way it should be done generally. this may be the problem when the X-lib's are installed dynamically only. How did you install SDL?
When I try to compile the program you posted, I get no errors (only warnings), either using the sdl-config stuff + #include "SDL.h", or using "gcc example1.c -o example1 -lSDL -lpthread" with #include <SDL/SDL.h>. (on Debian)
According to the SDL website, mandrake (and slackware) install KDE in non standard folders, so I added these lines to ld.so.conf, as suggested, but still to no avail
/usr/lib
/opt/kde/lib
I installed the libraries from rpms on a CD, which I think came with Linux Mandrake. I am starting to think it is a problem with the OS. Perhaps it is time to go back to SuSE.
libSDL.a resides in /usr/lib
libSDL.so does not turn up when i try to 'locate' it as a normal user. But as root 'locate' does find it.
I have tried therefore to compile as root but the results arent any different.
Perhaps mandrake is a less ideal distro for the developer.
by unholy I installed the libraries from rpms on a CD
<cut />
libSDL.a resides in /usr/lib
libSDL.so does not turn up when i try to 'locate' it as a normal user. But as root 'locate' does find it.
from what ive heard and from the questions ive answered before, mandrake is a bit of a nightmare for development purposes
you say you installed rpm's, were they the normal, development, or static-development rpms because the presence of libSDL.a but not libSDL.so make me think youve installed the static-development rather than the development rpm. but i could be wrong as i dont know much about mandrake/rpms
If libSDL.so wasnt readable to normal users, at least root should have been able to install it. I think maybe Mandrake is the problem. Its a pity. I've tried several distros, and found Mandrake struck the balance the best. But development is a must for me, so perhaps I will try another of the distros I have here on DVD (SuSE 82., Debian Woody Stable, Gentoo, Slackware, Fedora).
Sorry for being late, but your code was quite useful for me, thanks for that, and it compiles successfully easily too....due to a few errors you have:
a. Use <SDL.h> instead. Some error output reduced.
b. It is a C++ program, so please use ".cpp" instead of ".c". "gcc" will use different binaries to execute the ".cpp" vs ".c". More errors reduced.
c. After I change "gcc" to "g++" all error got eliminated, so the working commandline is:
(where mysdl_example.cpp is the code you posted earlier.)
My env is Ubuntu 9.04).
A good piece of reference code.
Thanks.
PS:
One of the error I got is:
undefined reference to `__gxx_personality_v0'
this was because I had used "gcc" to compile the "xxx.cpp" instead of "g++" - because I thought gcc is intelligent enough to use g++ just by the recognizing the extension is ".cpp". But no:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.