0

My codeblocks isn't finding the SDL2main and SDL2.dll files. Note that I added path and the compiler auto detected the include and lib library correctly . I also moved the SDL2.dll file to both System32 and SystemWOW64 file . The one I am using is i686-w64-mingw32 file. Processor is Intel Pentinum E5800 and the os is Windows 7 Ultimate 64 bit OS . The code I am trying to run is below -

#include<iostream>
#include<SDL2/SDL.h>
int main()
{
    if(SDL_Init(SDL_INIT_VIDEO)<0)
    {
         std::cerr<<SDL_GetError();
         return -1;

    }
     SDL_Window* window=SDL_CreateWindow("",0,0,240,240,SDL_WINDOW_SHOWN);
     if(window)
{
std::cout<<"Window was created\n";
SDL_DestroyWindow(window);
}
else
{
std::cerr<<SDL_GetError();
}
SDL_Quit();
return  0;
}

The debugger said : ld.exe - ld didn't find -lSDL2main

ld.exe - ld didn't find -lSDL2.dll

ld is quiting with return value 1

Where is the problem ?

  • Use vcpkg to install & integrate third party libraries to your project. It makes things a lot more easier. – seccpur Jul 18 '21 at 13:42
  • 1
    *"moved the SDL2.dll file to both System32 and SystemWOW64"* This is a bad, bad idea! Those files should placed next to your (future) `.exe`. Next: your linker is looking for `.a` files (I think modern MinGW can link `.dll` directly, but `.a` should give you less problems). CB should have a "linker search path" setting, where you should add the directory with the `.a` files. If this doesn't help (and neither does the thread I linked), please tell. – HolyBlackCat Jul 18 '21 at 13:44
  • @seccpur A package manager is a good idea, but isn't vcpkg intended primarily for MSVC? For MinGW there's MSYS2. – HolyBlackCat Jul 18 '21 at 13:45
  • the SDL2.dll file is from bin folder (note : not the libSDL2.dll.a) . I heard that I had to move it to System32 and SytemWOW64 ? –  Jul 18 '21 at 14:14
  • So I tried moving SDL2.dll to MinGW's bin folder, but no good . the path to libSDL2main.a and libSDL2.dll.a was already correct. But still the problem persists; –  Jul 18 '21 at 14:41
  • 1
    Please begin your comments with `@username`, otherwise I don't get notifications. *"I heard that I had to move it to System32 and SytemWOW64"* You heard wrong. *"tried moving SDL2.dll to MinGW's bin folder"* You don't need to do that. In general, it's a good idea to not touch your compiler installation. *"the problem persists"* Please read the post I linked (at the top of your question), it explains (almost) everything you need to know. – HolyBlackCat Jul 18 '21 at 15:10

0 Answers0