1

There are quite a few similar topics on SO regarding this but I have exhausted all the suggestions on 15 similar threads.

Upon running tutorial code utilizing the SDL library, the IDE is complaining of "undefined reference" to all functions pertaining to SDL.

Situation

Architecture: 64 bit

IDE: CodeBlocks 16.01

Compiler: GNU GCC

What I have tried to do

1) I told the compiler to find header under directory: .....\i686-w64-mingw32\include\SDL2 using relative paths

I did NOT select \include NOR did I select .....\x86_64-w64-mingw32\include\SDL2

2) I told compiler to find library files under directory: .....\i686-w64-mingw32\lib using relative paths

I did NOT select ....\lib NOR did I select .....\x86_64-w64-mingw32\lib

3) When linking the libraries, I included four libraries under the directory ....\i686-w64-mingw32\lib and NOT the other directories as mentioned above.

4) The order in which the libraries were linked are as follows:

SDL2main.lib

SDL2.lib

SDL2test.lib

5) I ensured that the properties of main.c were such that compile file was checked, link file was checked, and the belongs in targets debug and release were both checked.

Build log:

-------------- Build: Debug in Snake Game (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -L......\Downloads\SDL2-devel-2.0.4-mingw\SDL2-2.0.4\i686-w64-mingw32\lib -o "bin\Debug\Snake Game.exe" obj\Debug\main.o -lmingw32 ......\Downloads\SDL2-devel-2.0.4-mingw\SDL2-2.0.4\i686-w64-mingw32\lib\libSDL2main.a ......\Downloads\SDL2-devel-2.0.4-mingw\SDL2-2.0.4\i686-w64-mingw32\lib\libSDL2.a obj\Debug\main.o: In function SDL_main': C:/XXX/XXX/XXX/XXX/XXX/main.c:9: undefined reference toSDL_WM_SetCaption'

The log goes on and on with undefined references.

Can anybody guide me in solving this linking problem?

6
  • What compiler? MinGW? Commented Sep 15, 2016 at 22:03
  • please include the full link trace provided by code::blocks: command and output. Commented Sep 15, 2016 at 22:04
  • @HolyBlackCat GNU GCC Commented Sep 15, 2016 at 22:18
  • What OS then? Windows? Commented Sep 15, 2016 at 22:19
  • @HolyBlackCat Yes Commented Sep 15, 2016 at 22:21

1 Answer 1

2

There is no SDL_WM_SetCaption in SDL2. Your code is likely to be using older SDL 1.2. Either use correct library or modify your code e.g following https://wiki.libsdl.org/MigrationGuide

Sign up to request clarification or add additional context in comments.

12 Comments

I made the following changes: I copied in SDL2 code as you have mentioned.
I am now getting an error "SDL.h: No such file or directory" which has now become a compiler search problem. I have left the directories the same. I included the directories as both relative and non-relative. I have tried to change #include <SDL.h> to #include "SDL.h". No luck
I'm not going to do a guesswork, not without source and compile line. Maybe you should add source code of minimal program you having errors with to the question. Or just take any SDL2 example to start with. If your test program uses SDL_WM_SetCaption - clearly it is not for SDL2 and you should not follow that tutorial of yours (or switch to SDL1, which I don't recommend). It is very likely you'll hit a very different sort of linking errors; it would be much simpler to use dynamic libraries for a beginner.
I have started in an absolute clean slate: My only source code is:
#include <SDL.h> #include <stdio.h> //Screen dimension constants const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; int main( int argc, char* args[] ) { }
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.