I'm trying to set up my Code::Blocks installation to work with the SDL2 graphics API. As the documentation suggests, once I had everything installed and specified correctly, I tried the
SDL_Init(SDL_INIT_EVERYTHING)
test, as:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <SDL2/SDL.h>
int main (int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
printf("\nSDL2 could not be initialized! Code: %s\n", SDL_GetError());
}
return EXIT_SUCCESS;
}
However, I got the following errors:
...in function 'SDL_Main':
undefined reference to `SDL_Init`
undefined reference to `SDL_GetError`
undefined reference to 'WinMain@16'
I looked these errors up and they seem to be due to CodeBlocks using a 32-bit compiler, but I'm using the 64-bit SDL2 library. Which makes sense, as my linked options are:
-lmingw32 -lSDL2main -lSDL2
So, I used MinGW's WinBuilds
tool to download the 64-bit MinGW fork, which gave me a massive amount of files in a new /mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/...
folder. Then I went to CodeBlocks' Settings -> Compiler -> Toolchain Executables
and pointed the respective compiler executables at the exe's in bin
. My first thought was to then change -lmingw32
to -lmingw64
, but this doesn't work. I get the error:
cannot find -lmingw64
At this point I'm not sure what I've done correctly, incorrectly, what is broken/working etc. and would really appreciate any help possible.
It may also be worth noting that I extracted the 64-bit compiler to C:\MinGW
and pointed CodeBlocks at C:\MinGW\bin
as the compiler installation directory. When I click Auto-Detect
, it seems happy enough and states it has automatically found the GCC compiler in that location. Therefore, it must be my -lmingw64
flag that is wrong, or something else I have specified.
Edit: The 64-bit compiler was set up and detected correctly but continued to produce errors relating to SDL
functions:
||=== Build: Debug in Initialization_Test (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `SDL_main':|
C:\C\SDL_C_Graphics\Init_Test\Initialization_Test\main.cpp|8|undefined reference to `_SDL_Init'|
C:\C\SDL_C_Graphics\Init_Test\Initialization_Test\main.cpp|10|undefined reference to `_SDL_GetError'|
C:\C\SDL_C_Graphics\Init_Test\Initialization_Test\main.cpp|10|undefined reference to `_printf'|
obj\Debug\main.o||In function `__tcf_0':|
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iostream|74|undefined reference to `__ZNSt8ios_base4InitD1Ev'|
obj\Debug\main.o||In function `__static_initialization_and_destruction_0':|
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iostream|74|undefined reference to `__ZNSt8ios_base4InitC1Ev'|
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iostream|74|undefined reference to `_atexit'|
C:\SDL_Dev\SDL2-2.0.12\x86_64-w64-mingw32\lib\libSDL2main.a(SDL_windows_main.o)||In function `main_getcmdline':|
\Users\valve\release\SDL\SDL2-2.0.12-source\foo-x64\..\src\main\windows\SDL_windows_main.c|71|undefined reference to `SDL_main'|
||error: ld returned 1 exit status|
||=== Build failed: 8 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Command CodeBlocks may be executing for compilation, in separate log window:
x86_64-w64-mingw32-g++.exe -LC:\SDL_Dev\SDL2-2.0.12\x86_64-w64-mingw32\lib -LC:\SDL_Dev\SDL2-2.0.12\x86_64-w64-mingw32\lib -LC:\SDL_Dev\SDL_Img\SDL2_image-2.0.5\x86_64-w64-mingw32\lib -LC:\SDL_Dev\SDL_Mixer\SDL2_mixer-2.0.4\x86_64-w64-mingw32\lib -L"C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib" -o bin\Debug\Initialization_Test.exe obj\Debug\main.o -lmingw32 -lSDL2main -lSDL2 -lmingw32 -lSDL2main -lSDL2.dll -luser32 -lgdi32 -lwinmm -ldxguid
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `obj\Debug\main.o' is incompatible with i386:x86-64 output
-lmingw32
. – HolyBlackCat-lmingw32
, and while it seems to find the compiler now, I'm just back to the originalundefined reference
errors to theSDL
functions. There must be something else that I'm missing. – RowanWinMain@16
or not? – HolyBlackCat