0
votes

I'm pretty new to using 3rd party libraries and such, and I need some help getting Eclipse CDT configured to link to the dynamic SDL2.dll library and be able to read the code from the header files in this 3rd party library. A lot of examples seem to be of linux system set-ups using GCC and such, but I'm trying to get it to work with the Visual Studio toolchain already installed on my PC.

Path to header files: C:\SDL2-2.0.5\include

Path to .dll and .lib files: C:\SDL2-2.0.5\lib\x64

Code:

#include "C:\SDL2-2.0.5\include\SDL.h"

int main() {
    SDL_SetMainReady();
    if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)!=0){
        SDL_Log("Unable to initialize SDL: %s",SDL_GetError());
        return 1;
    }

    return 0;
}

I've tried adding the include path to the header files under Project>Properties>C/C++ General>Paths and Symbols>Includes>GNU C++(and GNU C), and I've tried adding the library path to "SDL2.dll" under Project>Properties>C/C++ General>Paths and Symbols>Libraries. The IDE still said it was unable to resolve the function calls; despite there being no issue with the #include "C:\SDL2-2.0.5\include\SDL.h" line.

I also tried adding the library path under Project>Properties>C/C++ Build>Settings>Tool Settings>Linker(link)>Libraries. Under "Additional libpath" i put: "C:\SDL2-2.0.5\lib\x64" and under "Libraries" I put: "C:\SDL2-2.0.5\lib\x64\SDL2.dll"; still with no success.

I even tried adding the include path to the .h files in the INCLUDE environment variable and the path to the .dll file in the PATH envirnment variable under Project>Properties>C/C++ Build>Environment.

Any help would be greatly appreciated.

1

1 Answers

0
votes

On Windows, dynamic libraries have two parts: the .dll that contains the executable code and is needed at runtime and a .lib which is the import library that tells the linker to find the externals in the .dll. So, under "Libraries" you need to specify the import library (.lib). And put the .dll somewhere the executable can find it at runtime, e.g. in the same folder.