0

I'm following a lesson on C++ on Udemy and seem to have fallen at the first hurdle for creating the program.

I've added all of the SDL Header files and included SDL.H as the lessons indicate.

I've done nothing with the DLL files which where provided in the SDL Default download.

My code is as follows:

#define SDL_MAIN_HANDLED
#include <iostream> 
#include <SDL.h>
using namespace std;

int main() {

    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        cout << "SDL init failed" << endl;
        return 1;
    }

    cout << "SDL Init succeeded" << endl;

    SDL_Quit();

    return 0;
}

However, I get the following errors upon compiling:

Error LNK2019 unresolved external symbol _SDL_Init referenced in function _main ParticleProjectNEW ParticleProgram\ParticleProjectNEW\Source.obj 1

Error LNK2019 unresolved external symbol _SDL_Quit referenced in function _main ParticleProjectNEW \ParticleProgram\ParticleProjectNEW\Source.obj 1

  • 4
    You need to link with the `.lib` file for SDL ... – ChrisMM Jan 02 '20 at 18:03
  • 1
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – UnholySheep Jan 02 '20 at 18:05
  • ***I've done nothing with the DLL files which where provided in the SDL Default download.*** These have nothing to do with the current error but will eventulaly need to be in the same folder as your executable or you have to change your `PATH` environment variable to tell windows where to look for those dlls. Note that Debug and Relase will likely have different .dlls and different .lib files. – drescherjm Jan 02 '20 at 18:07
  • this answer might give you some ideas how to fix it: https://stackoverflow.com/questions/33008574/how-does-auto-linking-libraries-in-c-work – marcinj Jan 02 '20 at 18:07
  • I've tried using the option from @marcinj and that didn't work. – Eddie Stubbington Jan 02 '20 at 18:24
  • I managed to find the problem that caused this... I had been using 64 bit version of SDL but was building in 32 bit (Or something along those lines...) therefore they where not identical. – Eddie Stubbington Jan 02 '20 at 23:03

0 Answers0