LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 08-21-2011, 04:03 PM   #1
searching_for_answers
Member
 
Registered: Sep 2009
Location: Sweden
Distribution: Mandriva
Posts: 44

Rep: Reputation: 21
SDL and KDevelop 4, project setup


I'm getting "undefined reference to `SDL_Init'" when I try to run
Code:
#include <iostream>
#include <SDL/SDL.h>

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

    SDL_Init(SDL_INIT_VIDEO);
    std::cout << "SDL is running" << std::endl;    
    SDL_SetVideoMode(720,480,32,SDL_SWSURFACE);
    SDL_Init(SDL_INIT_TIMER);
    SDL_Delay(2000);
    SDL_Quit();
    
    return 0;
}
I know this has something to do with linkers and libraries, I've also searched around a lot but none of the solutions are up to date.

For example: KDevelop & SDL

Quote:
Originally Posted by Relja View Post
I don't know about the documentation, but my SDL program works fine with KDevelop.

All I needed to put is:
Project->Project Options->Configure Options:

C/C++ preprocessor flags (CPPFLAGS):
`sdl-config --cflags`

Linker flags (LDFLAGS):
`sdl-config --libs`

and in
Automake Manager->Options:
Compiler flags for C__ compiler (CXXFLAGS):
`sdl-config --cflags --libs`

And it works ok...
Problem is that this solution is out dated. 'Project Options' and 'Automake Manager' do not exist, or if they're just well hidden in KDevelop 4.2.

How do I setup a SDL-project in KDevelop 4?
 
Old 08-23-2011, 01:19 AM   #2
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
the automake manager was in kdevelop3 and is not part of kdevelop4

you can use cmake with kdevelop4, for cmake there is a find_sdl module.

what you need is libSDL and libpthread

so it usually it is enough to call
g++ sdltest.cpp -lSDL -lpthread -o sdltest
 
0 members found this post helpful.
Old 08-24-2011, 05:41 AM   #3
searching_for_answers
Member
 
Registered: Sep 2009
Location: Sweden
Distribution: Mandriva
Posts: 44

Original Poster
Rep: Reputation: 21
Quote:
Originally Posted by a4z View Post
the automake manager was in kdevelop3 and is not part of kdevelop4

you can use cmake with kdevelop4, for cmake there is a find_sdl module.

what you need is libSDL and libpthread

so it usually it is enough to call
g++ sdltest.cpp -lSDL -lpthread -o sdltest
I could have mentioned that I got both libSDL1.2-dev and it also seems that lpthread thing is installed. I've got a SDL-program running in Code_::Blocks but I want it to run just as smooth (hopefully smoother) in KDevelop.

I can see the cmake settings (project configuration) but I don't understand what you're recommending me to do.
 
Old 08-24-2011, 09:40 AM   #4
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
if you make a cmake project and add options via gui, kdevelop will alter your CMakeLists.txt file that belongs to the project

in this file there will be something like
add_executable( yourprogram source.cpp file.cpp list.cpp )

linking via cmake works like that, add a line into the CMakeLists.txt (after add_executable):
target_link_libraries( yourprogram SDL lpthread}

that should do it.


could be that there are some gui options in kdevelop, but I do not have installed it currently and so I can not check this
 
1 members found this post helpful.
Old 08-28-2011, 07:54 AM   #5
searching_for_answers
Member
 
Registered: Sep 2009
Location: Sweden
Distribution: Mandriva
Posts: 44

Original Poster
Rep: Reputation: 21
Thread solved

You were right.

Enter the project folder and edit CMakeList.txt accordingly. This how it looks when it's done:
Code:
project(test2)

add_executable(test2 main.cpp)
target_link_libraries( test2 SDL pthread)
Notice that there there isn't any 'l' before pthread.

If you're new to KDevelop and get this error msg: "No valid executable specified" it means that you have to go Run>Configure Launches>. Select your project name to the left, press +, select the project again under project target.
 
  


Reply

Tags
kdevelop, kdevelop4, sdl



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
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
KDevelop & SDL Corant Programming 4 07-15-2004 06:31 AM
KDevelop and SDL Eponick Linux - Software 1 06-20-2004 12:04 AM
KDevelop and no QT project possible? Misel Slackware 2 11-03-2003 02:18 PM
Cannot see Open GL project in KDevelop project wizard SparceMatrix Programming 2 08-07-2002 11:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:59 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration