LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   SDL init undefined reference (https://www.linuxquestions.org/questions/programming-9/sdl-init-undefined-reference-751268/)

hua 08-30-2009 10:30 AM

SDL init undefined reference
 
Hi
I have started to use kdevelop4 (3.9.91) on my ne slackware64 13 Desktop. I was developing software which uses SDL in earlier version of slackware 12.2. (I don't know which version of kdevelop).
Now I tried use the same code in kdevelop4 and at build time I get an undefined reference for SDL_Init function. It gives no sense because in #include SDL/SDL.h I can see that SDL_Init function is included.

The export of code stands for me in copy the .cpp source of the main function into newly created c++ project in kdevelop4. I get lot more undefined reference messages for 26 SDL functions which I can locate in included header files.

I noticed that the SDL headers library changed a little and now I have lots of header files like SDL_video.h, SDL_config.h, SDL_main.h. There are 36 header files for SDL in the /usr/include/SDL folder. May it be that the old header file SDL.h have included everything in one and I need to Include more header files?

These is the list of existing header files in /usr/include/SDL/:
Quote:

SDL.h
SDL_active.h
SDL_audio.h
SDL_byteorder.h
SDL_cdrom.h
SDL_config.h
SDL_cpuinfo.h
SDL_endian.h
SDL_error.h
SDL_events.h
SDL_getenv.h
SDL_image.h
SDL_joystick.h
SDL_keyboard.h
SDL_keysym.h
SDL_loadso.h
SDL_main.h
SDL_mixer.h
SDL_mouse.h
SDL_mutex.h
SDL_name.h
SDL_net.h
SDL_opengl.h
SDL_platform.h
SDL_quit.h
SDL_rwops.h
SDL_stdinc.h
SDL_syswm.h
SDL_thread.h
SDL_timer.h
SDL_ttf.h
SDL_types.h
SDL_version.h
SDL_video.h
begin_code.h
close_code.h
These are the headers I have Included:
Quote:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>
#include <cstdlib>
#include <SDL/SDL_video.h>
#include <iomanip>
Thanks for any suggestion

Andrew85 08-30-2009 10:48 AM

Hi,

I'm a new commer in Linux Graphics Programming field. Please may i know how can you get exactly enough 36 headers like that in SDL directory . For my case i always missed the header SDL_image.h .

I have tried to reinstall SDL_image-1.2.3.rpm and later SDL_image-1.2.7.rpm . For 1.2.3 it show no error but the header SDL_image.h still missing. And for 1.2.7-1 there are 2 dependencies failures : Libc.so.6 is missing and RTLD is missing. Can anyone suggest me a solution please.

I sincerely apologize if my post has created any inconvinience. And i hope to hear a reply soon.

Your sincerely

Andrew.

hua 08-30-2009 11:06 AM

I have the new slackware 13 distribution. It uses the package SDL 1.2.13. The main question is what linux distribution you are using? The version 13 of slackware is very new. (released 27.8.) I cannot help you with managing the new version of SDL package into your distribution. The only solution I know - install slack 13.;)
But as you can see it is possible that there are still some problems with it. Because the code I am using for my graphic application was running with no problem in previous version of slackware (12.2)
Regards
Zoltan

mjsurette 08-31-2009 01:10 AM

An undefined reference is a linking issue, not a header issue. Check that you have the proper linking information for your libraries.

hth

Mike

hua 08-31-2009 01:59 AM

Thanks for your reply.
Quote:

Originally Posted by mjsurette (Post 3663506)
An undefined reference is a linking issue, not a header issue. Check that you have the proper linking information for your libraries.

Sorry that i am awkward but how can I do that?

Andrew85 08-31-2009 04:31 AM

Quote:

Originally Posted by hua (Post 3662926)
I have the new slackware 13 distribution. It uses the package SDL 1.2.13. The main question is what linux distribution you are using? The version 13 of slackware is very new. (released 27.8.) I cannot help you with managing the new version of SDL package into your distribution. The only solution I know - install slack 13.;)
But as you can see it is possible that there are still some problems with it. Because the code I am using for my graphic application was running with no problem in previous version of slackware (12.2)
Regards
Zoltan

Hi Zoltan, i used Red Hat Enterprise Linux 4 and i found that there always a librarie missing and header missing there.So any suggestion ? Should i switch to other OS ? Where can i download Slackware 13 ? And also Debian ?

hua 08-31-2009 06:27 AM

Each distribution uses its own packaging system. If you cannot find the package for your distribution you have to take care about it yourself. (create a package from source or compile the source (usually C++ code) right into your distribution)
Since I have no experience with Red Hat linux I cannot guide you to implement a new version of SDL into it. There can be other dependencies which I do not know about. I can only guide you to use slackware. You can get it here:
http://www.slackware.com/getslack/torrents.php
Its a torrent iso - you can choose weather you use CDs or DVD, 32 bit or 64 bit.

But before this you need to know slackware is different and you need to learn the basic install process. (From my point of view its very simple, because I already walk through the install several times) If you decide to setup slackware you have to be prepared to solve possible "difficulties". I can help you with that.

I cannot tell you how difficult would be the other way - implementing the new SDL version into redhat. You have to decide yourself.
If you decide to try slackware - create a thread in linuxdistros > slackware > Newbie slackware user - install.
I will find your post and guide you there. There are lots of helpful guys (and girls) who will be happy to help out a newbie slackware users.
Good luck

shuuhen 08-31-2009 08:17 AM

The gcc info page will have much more info, but basically you want to do

gcc -lSDL -o sdl_program sdl_program.c

or something similar depending on how your project is set up. The -L option may also be of interest to you (read the info page for that one).

mjsurette 08-31-2009 08:50 AM

Quote:

Originally Posted by shuuhen (Post 3663897)
The gcc info page will have much more info, but basically you want to do

gcc -lSDL -o sdl_program sdl_program.c

or something similar depending on how your project is set up. The -L option may also be of interest to you (read the info page for that one).

gcc links libraries in the order that they are given, so you would actually need

gcc -o sdl_program sdl_program.c -lSDL

because your program generates references to libSDL.so

You might be interested in http://lazyfoo.net/SDL_tutorials/index.php

It shows how to set up SDL with various systems, including KDevelop.

hua 08-31-2009 11:08 AM

Quote:

Originally Posted by mjsurette (Post 3663948)
It shows how to set up SDL with various systems, including KDevelop.

Thanks its a very good link. My problem will be with the new kdevelop version (kdevelop4 v. 3.9.95).

I have used SDL exactly the way how it is showed on the link above before kdevelop version 3.9.91. I start a new project wizard which gives me the option of the simple SDL program. Probably this step makes everything for me what is needed for SDL library linking.

But now when I am creating a new project in kdevelop4 I cannot choose simple SDL program. It has very few project templates. So all the steps what the old kdevelop done for me in previous versions I need to do on my own. But how??

Quote:

gcc -o sdl_program sdl_program.cpp -lSDL
What does this command do? Compile the source with the SDL librarie or just generates some reference file to SDL libraries?
I would like to done this the way that my kdevelop build the executable directly from the kdevelop application. I was using build from the project menu.

I get this error:
Quote:

project2.cpp:7:24: error: project2.moc: No such file or directory
project2.cpp:22:24: error: QApplication: No such file or directory
project2.cpp: In constructor 'project2:: project2()':
project2.cpp:58: error: 'qApp' was not declared in this scope
project2.cpp: In member function 'void project2::setupActions()':
project2.cpp:84: error: 'qApp' was not declared in this scope

mjsurette 08-31-2009 12:19 PM

Quote:

Originally Posted by hua (Post 3664088)
Thanks its a very good link. My problem will be with the new kdevelop version (kdevelop4 v. 3.9.95).

I have used SDL exactly the way how it is showed on the link above before kdevelop version 3.9.91. I start a new project wizard which gives me the option of the simple SDL program. Probably this step makes everything for me what is needed for SDL library linking.

But now when I am creating a new project in kdevelop4 I cannot choose simple SDL program. It has very few project templates. So all the steps what the old kdevelop done for me in previous versions I need to do on my own. But how??


What does this command do? Compile the source with the SDL librarie or just generates some reference file to SDL libraries?
I would like to done this the way that my kdevelop build the executable directly from the kdevelop application. I was using build from the project menu.

I get this error:

I'm afraid I've never used kdevelop so I can't help you with that, but it looks like it's missing a project template (just a guess).

The command

gcc -o sdl_program sdl_program.cpp -lSDL

compiles your program and creates references to the libSDL.so library. If you prefer to have sdl linked in you'd add a -static directive. It would then load the referenced functions from libSDL.a directly into your program.

Usually this would be found in your Makefile.

Mike

ta0kira 08-31-2009 01:02 PM

Quote:

Originally Posted by Andrew85 (Post 3662914)
Hi,

I'm a new commer in Linux Graphics Programming field. Please may i know how can you get exactly enough 36 headers like that in SDL directory . For my case i always missed the header SDL_image.h .

I have tried to reinstall SDL_image-1.2.3.rpm and later SDL_image-1.2.7.rpm . For 1.2.3 it show no error but the header SDL_image.h still missing. And for 1.2.7-1 there are 2 dependencies failures : Libc.so.6 is missing and RTLD is missing. Can anyone suggest me a solution please.

I sincerely apologize if my post has created any inconvinience. And i hope to hear a reply soon.

Your sincerely

Andrew.

In some cases you'll have to install headers separately from the library. In other words, you'll often have the library installed but the headers to use it won't be there. You'll probably need to locate a version of the package ending in -dev or one that otherwise indicates it's for development.
Kevin Barry


All times are GMT -5. The time now is 11:30 PM.