[C++] SDL2 - Undefined references to functions at school

Need help with C, C++, perl, python, etc?

[C++] SDL2 - Undefined references to functions at school

Postby Baodoap » 2016-01-29 18:45

Hello,

I try to compile a c++ code with the library SDL2 at school in debian x32 but I got few error:

main.cpp:(.text+0x39): undefined reference to `SDL_CreateWindow'
main.cpp:(.text+0x59): undefined reference to `SDL_CreateRenderer'
main.cpp:(.text+0x69): undefined reference to `SDL_RenderPresent'
main.cpp:(.text+0x75): undefined reference to `SDL_Delay'
collect2: error: ld returned 1 exit status


My main.cpp:

Code: Select all
#include "SDL2/SDL.h"

int main()
{
    SDL_Window *screen;
    SDL_Renderer *renderer;

    screen = SDL_CreateWindow("test", SDL_WINDOWPOS_CENTERED, 20, 500, 300, SDL_WINDOW_SHOWN);
    renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_PRESENTVSYNC);
    SDL_RenderPresent(renderer);
    SDL_Delay(1);
    return 0;
}


In terminal, I write:

g++ main.cpp -L. -lSDL2 -lSDL2main


In the same folder I have:
    A folder "SDL2" with all .h file
    The files:
      libSDL2.a
      libSDL2.dll.a
      libSDL2main.a

I already tried to replace the include by #include <SDL2/SDL.h> and write in the console:
g++ main.cpp -I(PATH TO MY INCLUDE FILES ON USB KEY) -L(PATH TO MY .a FILES AND .lib FILES ON USB KEY) -lSDL2 -lSDL2main

but I had the same thing.

Because I am at school, I don't have root permission so I can't install anything.

In my own computer on windows or debian it work perfectly.
Baodoap
 
Posts: 7
Joined: 2016-01-29 18:36

Re: [C++] SDL2 - Undefined references to functions at school

Postby tomazzi » 2016-01-29 19:08

Linking with libraries compiled for windows definitely won't work.
Odi profanum vulgus
tomazzi
 
Posts: 730
Joined: 2013-08-02 21:33

Re: [C++] SDL2 - Undefined references to functions at school

Postby Baodoap » 2016-01-29 19:18

But it work fine in my debian computer.
Baodoap
 
Posts: 7
Joined: 2016-01-29 18:36

Re: [C++] SDL2 - Undefined references to functions at school

Postby tomazzi » 2016-01-29 19:28

No, it does not - at least not with the files You've listed.
It works only because You have SDL libs already installed in the default search path (/usr/lib/... and /usr/include/SDL).
Odi profanum vulgus
tomazzi
 
Posts: 730
Joined: 2013-08-02 21:33

Re: [C++] SDL2 - Undefined references to functions at school

Postby Baodoap » 2016-01-29 19:30

If I took what is already installed and put them in the same directory of main.cpp, will it work ?
Baodoap
 
Posts: 7
Joined: 2016-01-29 18:36

Re: [C++] SDL2 - Undefined references to functions at school

Postby tomazzi » 2016-01-29 19:48

If it's the same architecture and the same Debian version, then it should work.
But, there may be issues with other header files which are referenced by SDL - they must exist on the target system.

Anyway - it's really strange - if You are learning programming with SDL, then I would expect that all the necessary files are already installed on Your system.
Perhaps You should ask Your professor for help ??
Odi profanum vulgus
tomazzi
 
Posts: 730
Joined: 2013-08-02 21:33

Re: [C++] SDL2 - Undefined references to functions at school

Postby Baodoap » 2016-01-29 20:14

Only SDL 1.2 is installed. I want to compile with SDL 2. (The professors will no update their system and I can't boot on a live CD/USB)

My computer is debian x64 and the school computers are debian x32 will it work even so ?
Baodoap
 
Posts: 7
Joined: 2016-01-29 18:36

Re: [C++] SDL2 - Undefined references to functions at school

Postby tomazzi » 2016-01-29 20:32

SDL2 is in the repositories.
AMD64 libs have no chances to work on x86. (f.e. due to different ELF format).

First, check what version of the SDL is installed on Your system at school - because I'm starting to think that You're trying to break open doors (by using incompatible libraries from the stick, instead those already installed).
Odi profanum vulgus
tomazzi
 
Posts: 730
Joined: 2013-08-02 21:33

Re: [C++] SDL2 - Undefined references to functions at school

Postby Baodoap » 2016-01-29 21:00

SDL 1.2 is installed at school, I can tell this because we have a sample that use functions from SDL 1.2 and to compile this, we use -lSDL.

You're trying to break open doors

What do you mean, I don't understand ?
Baodoap
 
Posts: 7
Joined: 2016-01-29 18:36

Re: [C++] SDL2 - Undefined references to functions at school

Postby tomazzi » 2016-01-29 21:30

You can download the SDL2 DEB package for the Debian version which is used in Your school from here:
http://www.debian.org/distrib/packages

The packages You need are:
libsdl2-dev (headers)
libsdl2-xxxx (the library)
If You need additional modules, like for playing sounds, etc, then additional libraries may be required (libsdl2-mixer-dev, etc).

I suggest to first install what You need on Your system at home, then download all the necessary packages for the system which You're using at school.

You don't have to install the pkg's at school - instead, just extract the libs and link Your program against them.

Regards.
Odi profanum vulgus
tomazzi
 
Posts: 730
Joined: 2013-08-02 21:33

Re: [C++] SDL2 - Undefined references to functions at school

Postby Baodoap » 2016-01-29 22:01

I have downloaded libsdl2-2.0-0_2.0.2+dfsg1-6_i386.deb (https://packages.debian.org/jessie/i386 ... 0/download) and extracted it, but I don't find any libraries.
Baodoap
 
Posts: 7
Joined: 2016-01-29 18:36

Re: [C++] SDL2 - Undefined references to functions at school

Postby tomazzi » 2016-01-30 16:24

Baodoap wrote:I have downloaded libsdl2-2.0-0_2.0.2+dfsg1-6_i386.deb (https://packages.debian.org/jessie/i386 ... 0/download) and extracted it, but I don't find any libraries.


Oh, really? :roll:
1. libsdl2-2.0-0_2.0.2+dfsg1-6_i386.deb :: /usr/lib/i386-linux-gnu/libSDL2-2.0.so
2. libsdl2-dev_2.0.2+dfsg1-6_i386.deb :: /usr/lib/i386-linux-gnu/ :: <static lib versions here>

http://linux.die.net/man/1/dpkg-deb
Odi profanum vulgus
tomazzi
 
Posts: 730
Joined: 2013-08-02 21:33

Re: [C++] SDL2 - Undefined references to functions at school

Postby Baodoap » 2016-02-02 18:34

I did not know a .so file was a library, you taught me something.

So like you said, I extracted the libraries in the same folder of main.cpp and I used these different commands to compile but I got munch more undefined references:

g++ main.cpp -ISDL2 -L. -lSDL2 -lSDL2main

http://pastebin.com/bnYkT11B

g++ main.cpp -ISDL2 -L. -lSDL2-2.0 -lSDL2main

http://pastebin.com/ewp4vNQV

PS:
uname -a

give me this:
Code: Select all
Linux r10210 3.2.0-4-686-pae #1 SMP Debian 3.2.57-3 i686 GNU/Linux
Baodoap
 
Posts: 7
Joined: 2016-01-29 18:36

Re: [C++] SDL2 - Undefined references to functions at school

Postby tomazzi » 2016-02-02 23:54

"...undefined reference to dlopen" ...dlopen? are You kidding with me? Do You really don't know what does it mean? what the hell they teaching You? cooking? - definitely not a programming...

...I'm sorry, but I'm not going to waste my time in this case - learn how the dynamic library code is referenced - it'll suit You well in the future...\

[edit: explanation: not needed, in fact... ]
i.e. (if you're still in doubt:) dlopen is one of the most basic functions, which is making the operating OS running - it can not fail - never, ever - it's You who have failed to download a correct version of a library.
[/edit]
Odi profanum vulgus
tomazzi
 
Posts: 730
Joined: 2013-08-02 21:33

Re: [C++] SDL2 - Undefined references to functions at school

Postby commodorejohn » 2017-02-11 22:45

Reviving this thread because I'm having a similar issue. I have the SDL2 library and development headers installed from the repository (jessie,) but it keeps giving me undefined-reference errors for some (but not nearly all) of the SDL functions. I've tried it several ways based on some preliminary Googling and am following SDL's own guidelines on compiling/linking, but it just won't link for some reason. Here's the command and output:
Code: Select all
commodorejohn@devuan:~$ gcc sdltest.c `sdl2-config --cflags --libs` -o sdltest
/tmp/ccCtWq9W.o: In function `main':
sdltest.c:(.text+0x15f): undefined reference to `SDL_CreateRGBSurfaceWithFormat'
sdltest.c:(.text+0x2c2): undefined reference to `SDL_RendererFillRect'
sdltest.c:(.text+0x326): undefined reference to `SDL_RendererCopy'
sdltest.c:(.text+0x341): undefined reference to `SDL_RendererPresent'
collect2: error: ld returned 1 exit status

I really don't understand why this is happening. Any advice on resolving this issue?
commodorejohn
 
Posts: 35
Joined: 2011-06-29 10:26

Next

Return to Programming

Who is online

Users browsing this forum: No registered users and 6 guests

fashionable