2

so basicly i want to make a new sdl2 project (lastest version : 2.24.2) so i make a simple program that just print out the version of sdl :

#include <stdio.h>
#include "SDL2/SDL.h"

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

    SDL_version nb;
    SDL_GetVersion(&nb);

    printf("sdl version %d.%d.%d", nb.major, nb.major, nb.patch);

    return 0;
}

and i'm using this command to compile :

gcc src/*.c -o bin/sampleSDL -I include -L lib -lmingw32 -lSDL2main -lSDL2

and i get error :

c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\CDRIC~1\AppData\Local\Temp\ccaOMh5N.o:main.c:(.text+0x16): undefined reference to `SDL_GetVersion'
collect2.exe: error: ld returned 1 exit status

I use the 32bits version too.


also my project have this structure :

SampleSDLproject
|-bin
| |-SDL2.dll
| |-sdl2-config
|
|-include
| |-SDL2
| | |-the headers of sdl
|
|-lib
| |-like the sdl lib folder
|
|-src
| |-main.c

i tried installing some other c/c++ packages for mingw, installing new version of sdl (started with 2.24.1) but all this didn't worked

oh and i was forced to instal endian.h because of vscode


I found the error myself, i just needed to use the i686-w64-mingw32 folder instead of x86_64-w64-mingw32

Darkflame
  • 36
  • 2
  • 1
    *all this didn't worked*. What did it do? Same thing? Eat your cat? Details, my friend, we need details! – user4581301 Nov 02 '22 at 23:06
  • 2
    Good minimal example though. Doesn't get much better than that. – user4581301 Nov 02 '22 at 23:07
  • and which working directory are you compiling and linking this from? – Neil Butterworth Nov 02 '22 at 23:08
  • i'm compiling to the parent director of the project (sampleSDLproject) – Darkflame Nov 02 '22 at 23:10
  • the error message indicates that the linker has found the library, but can't find the function - have you got the spelling, case & other stuff right? or maybe it is in another library? – Neil Butterworth Nov 02 '22 at 23:17
  • no it's the right one, it's from a tutorial on youtube to start SDL2 and i just 'copied-paste' all he does (because i thought i was wrong somewhere while doing it before) and it don't work (but it work for him) also i tryed reinstall mingw and nothing changed – Darkflame Nov 02 '22 at 23:21
  • Probably better to not mention that the info came from a youtube tutorial. They haven't exactly covered themselves in glamour and respect around here. – user4581301 Nov 02 '22 at 23:22
  • vscode said it should work tho (i have the c/c++ extension) and also, check the sdl api and say that it shouldn't work :/ – Darkflame Nov 02 '22 at 23:23
  • vscode is not an AI - there is no way it can say that your program "should work" – Neil Butterworth Nov 02 '22 at 23:25
  • it detected no error* :/ – Darkflame Nov 02 '22 at 23:26
  • *c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\CDRIC~1\AppData\Local\Temp\ccaOMh5N.o:main.c:(.text+0x16): undefined reference to `SDL_GetVersion' collect2.exe: error: ld returned 1 exit status* is an error. Ergo an error was detected. I'll admit the error diagnostic isn't all that helpful in this case. – user4581301 Nov 02 '22 at 23:35
  • oh and it don't work only with sdl, if i try to link lua to a cpp project, it work, so... – Darkflame Nov 02 '22 at 23:35
  • i needed to use the `i686-w64-mingw32` ;( i wan't commit sucide – Darkflame Nov 02 '22 at 23:48
  • Link order can be important. The only needed library is `-lSDL2`. I have no problem (other than unused `argc` and `argv` warnings) with `gcc -Wall -Wextra -pedantic -Wshadow -std=c11 -Ofast -lSDL2 -o sdlver sdlver.c` – David C. Rankin Nov 03 '22 at 00:36
  • 1
    Reminder: clean up comments that are no longer needed, editing anything useful about the question into the question post. @Darkflame, if you found a solution, write up an answer describing what the problem was, how you solved it, and how/why the solution works. – rainbow.gekota Nov 03 '22 at 01:51
  • @DavidC.Rankin All three libs are normally needed on Windows (at least that's what `pkg-config` returns). You can get rid of the other two only if you `#undef main`, or something similar. – HolyBlackCat Nov 03 '22 at 08:32

0 Answers0