LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   SDL and KDevelop 4, project setup (https://www.linuxquestions.org/questions/programming-9/sdl-and-kdevelop-4-project-setup-898665/)

searching_for_answers 08-21-2011 04:03 PM

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 (Post 1044069)
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?:scratch:

a4z 08-23-2011 01:19 AM

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

searching_for_answers 08-24-2011 05:41 AM

Quote:

Originally Posted by a4z (Post 4450818)
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.

a4z 08-24-2011 09:40 AM

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

searching_for_answers 08-28-2011 07:54 AM

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.


All times are GMT -5. The time now is 04:47 PM.