0

I'm creating an C++ static library with code::blocks that call functions of the SDL library. The library compiles OK. I created annother project that will use the library I've created, all the build options are OK, I set the linker to work with the SDL and everything else, but, when I try to compile the project, I got Undefined Reference in the SDL functions. I solve this trouble by putting an call to SDL_Delay(1) function in the end of the main function.

It seems that the linker only found the SDL functions when I call at least one of them in the project that I'm compiling. Exist an more correct way to solve this?­

example:

#include "HW_Engine" // My static link library

void main(int argc, char *argv[]){
   HWE_Core *Engine_Core = new HWE_Core(); // this constructor calls some SDL functions
   ...
   SDL_Delay(1); // If I omit this, I have an Undefined reference for all the 
                 // SDL functions called in the HW_Engine library
}

thanks for the help!

Ivo Fritsch
  • 105
  • 7
  • 1
    Could you include the compiler parameters you are using? Are you correctly telling the linker which libraries to use? – mrks Oct 14 '16 at 13:51
  • 3
    "all the build options are OK" - pretty sure they're not, else you wouldn't be having linking issues. – UKMonkey Oct 14 '16 at 13:55
  • mingw32-g++.exe -L..\HW_Engine\bin\Debug -L..\HW_Engine\include -o bin\Debug\Engine_Tester.exe obj\Debug\main.o -lmingw32 -lSDL2main -lSDL2 -lHW_Engine ..\HW_Engine\bin\Debug/libHW_Engine.a – Ivo Fritsch Oct 14 '16 at 20:31
  • @IvoFritsch first why did you specified `HW_Engine` library twice, with -l and by path? Second, as it uses SDL it have to be before `-lSDL2`. Just put this library first, right after yout `.o`. Also your `-L..\HW_Engine\include` looks strange - `-L` specified path for libraryes, not for include directories. – keltar Oct 15 '16 at 04:32
  • Thanks for the answer, I will test soon I get in my PC, I will say if it works! – Ivo Fritsch Oct 16 '16 at 21:32

0 Answers0