What is wrong with this program?

I cannot find any syntax problems with this file, but it does not compile.
I have the SDL libraries, and I have compiled other programs that use SDL.
The errors are:

In function main':blitting-surfaces-sdl.c:(.text+0x19): undefined reference toSDL_Init’
:blitting-surfaces-sdl.c:(.text+0x22): undefined reference to SDL_GetError' :blitting-surfaces-sdl.c:(.text+0x45): undefined reference toSDL_Quit’
:blitting-surfaces-sdl.c:(.text+0x6e): undefined reference to SDL_SetVideoMode':blitting-surfaces-sdl.c:(.text+0x7c): undefined reference toSDL_GetError’
:blitting-surfaces-sdl.c:(.text+0xac): undefined reference to SDL_RWFromFile' :blitting-surfaces-sdl.c:(.text+0xbc): undefined reference toSDL_LoadBMP_RW’
:blitting-surfaces-sdl.c:(.text+0x149): undefined reference to SDL_UpperBlit' :blitting-surfaces-sdl.c:(.text+0x174): undefined reference toSDL_UpdateRect’
:blitting-surfaces-sdl.c:(.text+0x180): undefined reference to SDL_Delay' :blitting-surfaces-sdl.c:(.text+0x18b): undefined reference toSDL_FreeSurface’collect2: ld returned 1 exit status

Also, I have replaced the headers with both

#include </usr/include/SDL/SDL.h>
#include </usr/include/SDL/SDL_image.h>
#include </usr/include/SDL/SDL_video.h>

and

#include <stdlib.h>
#if defined(_MSC_VER)
#include “SDL.h”
#else
#include “SDL/SDL.h”
#endif

if the path is wrong, GCC reports that SDL.h is not found; but if it is correct, it does not list any problem finding headers, but still cannot ‘use’ them.

The program is:

#include <stdio.h>
#include <stdlib.h>

int main()
{
SDL_Surface *screen;
SDL_Surface *image;
SDL_Rect src, dest;

if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}

atexit(SDL_Quit);

screen = SDL_SetVideoMode(256,256,16,0);
if(screen == NULL) {
printf("Unable to set video mode: %s\n", SDL_GetError());
return 1;
}

image = SDL_LoadBMP(“pygame_icon.bmp”);
if(image == NULL) {
printf(“Unable to load bitmap.\n”);
return 1;
}

src.x = 0;
src.y = 0;
src.w = image -> w;
src.h = image -> h;

dest.x = 0;
dest.y = 0;
dest.w = image -> w;
dest.h = image -> h;

SDL_BlitSurface(image, &src, screen, &dest);

SDL_UpdateRect(screen, 0, 0, 0, 0);

SDL_Delay(3000);

SDL_FreeSurface(image);

return 0;

}---------------------------------
See the all-new, redesigned Yahoo.com. Check it out.

The linker doesn’t found the SDL libraries

Alexander Claffey ha scritto:> I cannot find any syntax problems with this file, but it does not compile.

I have the SDL libraries, and I have compiled other programs that use SDL.
The errors are:

In function main':blitting-surfaces-sdl.c:(.text+0x19): undefined reference toSDL_Init’
:blitting-surfaces-sdl.c:(.text+0x22): undefined reference to SDL_GetError' :blitting-surfaces-sdl.c:(.text+0x45): undefined reference toSDL_Quit’
:blitting-surfaces-sdl.c:(.text+0x6e): undefined reference to
SDL_SetVideoMode':blitting-surfaces-sdl.c:(.text+0x7c): undefined reference toSDL_GetError’
:blitting-surfaces-sdl.c:(.text+0xac): undefined reference to
SDL_RWFromFile' :blitting-surfaces-sdl.c:(.text+0xbc): undefined reference toSDL_LoadBMP_RW’
:blitting-surfaces-sdl.c:(.text+0x149): undefined reference to
SDL_UpperBlit' :blitting-surfaces-sdl.c:(.text+0x174): undefined reference toSDL_UpdateRect’
:blitting-surfaces-sdl.c:(.text+0x180): undefined reference to SDL_Delay' :blitting-surfaces-sdl.c:(.text+0x18b): undefined reference toSDL_FreeSurface’collect2: ld returned 1 exit status

Hello !

The code itself compiles without problems.
On Linux it should be no problem to use
#include “SDL.h”

#include <stdio.h>
#include <stdlib.h>

int main() {

Your main function should look like :

int main (int argc, char *argv []) {

Maybe an already installed SDL package is
getting in the way or something else.

I would delete all SDL and SDL*.devel Packages,
use make uninstall, download the latest SDL
version and compile it from the sources.

CU

Thanks for the help, but I have another question.

I was able to compile the program by adding compiler flags:
sdl-config --cflags --libs

But it feels like a patch-up for fixing the real link problem.

Furthermore, there is a larger program that I added the SDL code to,
and I need to modify the Makefile.
I add ‘sdl-config --cflags --libs’ and variations to CFLAGS,
SDL_CFLAGS, and SDL_LIBS but no success yet

Torsten Giebl wrote: Hello !

The code itself compiles without problems.
On Linux it should be no problem to use
#include “SDL.h”

#include
#include

int main() {

Your main function should look like :

int main (int argc, char *argv []) {

Maybe an already installed SDL package is
getting in the way or something else.

I would delete all SDL and SDL*.devel Packages,
use make uninstall, download the latest SDL
version and compile it from the sources.

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


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

If you are using G++ as your compiler, add the flags -lSDL -lSDL_image or
-lSDL_mixer for the respected libraries. I know that works on linux, Im not
sure about Windows though.On 8/5/06, Alexander Claffey wrote:

Thanks for the help, but I have another question.

I was able to compile the program by adding compiler flags:
sdl-config --cflags --libs

But it feels like a patch-up for fixing the real link problem.

Furthermore, there is a larger program that I added the SDL code to,
and I need to modify the Makefile.
I add ‘sdl-config --cflags --libs’ and variations to CFLAGS,
SDL_CFLAGS, and SDL_LIBS but no success yet

Torsten Giebl wrote:

Hello !

The code itself compiles without problems.
On Linux it should be no problem to use
#include “SDL.h”

#include
#include

int main() {

Your main function should look like :

int main (int argc, char *argv []) {

Maybe an already installed SDL package is
getting in the way or something else.

I would delete all SDL and SDL*.devel Packages,
use make uninstall, download the latest SDL
version and compile it from the sources.

CU


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


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


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

I used these flags in Makefile. the compiler still dies saying that SDL_Init and other functions do not exist. I would like to ask you for more ideas.

Matthew Little wrote: If you are using G++ as your compiler, add the flags -lSDL -lSDL_image or -lSDL_mixer for the respected libraries. I know that works on linux, Im not sure about Windows though.

On 8/5/06, Alexander Claffey <@Alexander_Claffey> wrote: Thanks for the help, but I have another question.

I was able to compile the program by adding compiler flags:
sdl-config --cflags --libs

But it feels like a patch-up for fixing the real link problem.

Furthermore, there is a larger program that I added the SDL code to,
and I need to modify the Makefile.
I add ‘sdl-config --cflags --libs’ and variations to CFLAGS,
SDL_CFLAGS, and SDL_LIBS but no success yet

Torsten Giebl wrote:

Hello !

The code itself compiles without problems.
On Linux it should be no problem to use
#include “SDL.h”

#include

#include

int main() {

Your main function should look like :

int main (int argc, char *argv []) {

Maybe an already installed SDL package is
getting in the way or something else.

I would delete all SDL and SDL*.devel Packages,
use make uninstall, download the latest SDL
version and compile it from the sources.

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


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


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


Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail Beta.