0

when my code is:

int WinMain(int argc, char **argv) {

    int SDL_Init(SDL_INIT_VIDEO);
    return 0;
}

it's working fine but when my code is:

int WinMain(int argc, char **argv) {

    if(SDL_Init(SDL_INIT_VIDEO) < 0) {
        // nothing here
    }
    return 0;
}

I'm getting this error: undefined reference to 'SDL_Init'

I'm on VSC 1.32.1 window 10 mingw32 6.3.0

NoxFly
  • 179
  • 1
  • 12
  • It means you forgot to link to your sdl libraries in the second example. The first example has nothing to do with sdl. – drescherjm Mar 08 '19 at 12:40
  • not sure if I was right in interpreting the question as "why the discrepancy?" If you merely want to fix the second, the proposed duplicate has the answer for you – 463035818_is_not_an_ai Mar 08 '19 at 12:44

1 Answers1

1

In your first code you delcare an int called SDL_Init, lets change the names to make it more obvious:

int WinMain(int argc, char **argv) {
    int variable_name(some_value);    
}

In your second code you call a function:

int WinMain(int argc, char **argv) {
    if(some_function(some_value) < 0) { }
}

Thats why in the first you dont get an error, but in the second you do. Seems like there is no some_function aka SDL_Init defined, which can be caused by not linking corretly, see here for how to fix that.

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185