0
\$\begingroup\$

I am using Lazy Foo's Production tutorials for making an SDL game in C in Xcode 6.1 - http://lazyfoo.net/tutorials/SDL/index.php#Hello%20SDL. I'm using Xcode 7 but I don't think they are very different.

In the second tutorial (http://lazyfoo.net/tutorials/SDL/02_getting_an_image_on_the_screen/index.php). I cannot seem to compile properly without an error regarding one of the functions.

The function prototype:

//Frees media and shuts down SDL
void close();

Then the function declaration:

void close()
{
    //Deallocate surface
    SDL_FreeSurface( gHelloWorld );
    gHelloWorld = NULL;

    //Destroy window
    SDL_DestroyWindow( gWindow );
    gWindow = NULL;

    //Quit SDL subsystems
    SDL_Quit();
}

And then the function call at the end:

close();

I am getting these errors and am not quite sure how to fix them. Other solutions online are for problems that are not quite the same as mine.

SDL_Tutorial/SDL_Tutorial/using_image.c:28:6: Conflicting types for 'close'

SDL_Tutorial/SDL_Tutorial/using_image.c:28:6: Conflicting types for 'close'

SDL_Tutorial/SDL_Tutorial/using_image.c:127:5: Implicit declaration of function 'close' is invalid in C99

SDL_Tutorial/SDL_Tutorial/using_image.c:127:11: Too few arguments to function call, expected 1, have 0

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any help would be much appreciated, as I am struggling to make progress with learning SDL game programming at the moment.

Thank you.

\$\endgroup\$
1
  • \$\begingroup\$ I'm sorry if question is irrelevant, I'm not familiar with tutorial. You are using C with procedure programming, there is no OOP, right? Is your close() function has overloaded version with different amount is parameters? Is it declared in the same file from which is get called? \$\endgroup\$
    – zhekazheka
    Commented Dec 12, 2016 at 18:57

1 Answer 1

1
\$\begingroup\$

The lazyfoo tutorials don't have the best coding practices. I can see two problems:

  • close is too generic of a name for a function. It's most likely conflicting with an existing function with the same signature. You should rename the function.
  • In C, void foo() is not the right way to declare "a function that takes no arguments and returns nothing". It's void foo(void). You should either fix the declaration, or compile your code as C++, as lazyfoo assumes (note that if you download their code their files are inside .cpp files). In C++ void foo() is a correct declaration.
\$\endgroup\$
6
  • \$\begingroup\$ Sorry I've replied a bit late, I've been quite busy. I've done what you said: I changed void close() to void close_game(void) and I'm glad to say those errors are gone, so thank you very much for that. However, I am still getting the error clang: error: linker command failed with exit code 1 (use -v to see invocation). Do you know why this might be? \$\endgroup\$
    – AkThao
    Commented Dec 16, 2016 at 17:09
  • \$\begingroup\$ You should google that error message to see if there's anything helpful. If that doesn't help, ask a new question. \$\endgroup\$ Commented Dec 22, 2016 at 0:58
  • \$\begingroup\$ @kashveyron, call up the build log in Xcode. If you hover your mouse arrow over the right end of the error message's line, there will be a little "three lines of text" icon button. Click that to see the full compiler output for the error message. That should include a list of the functions or globals (symbols) that the linker is missing. \$\endgroup\$
    – uliwitness
    Commented Jan 28, 2017 at 9:19
  • \$\begingroup\$ Ok I've done that and it seems the main error is 3 duplicate symbols for architecture x86_64. I have identified the 'duplicate symbols' as _main, _SCREEN_HEIGHT and _SCREEN_WIDTH. Then under each of them, it names the files that I am working on and the directory in which they are found. But I don't know anything more than that in terms of what 'duplicate symbols' actually means. \$\endgroup\$
    – AkThao
    Commented Jan 28, 2017 at 19:52
  • \$\begingroup\$ Sorry, I'm late, you may have solved your problem already, but if someone else ends up here: "symbol" is a catch-all term for a function, global variable, or const global variable, basically. Ignore the leading underscore in this case, that's a technical detail of the compiler. So it is saying that you have 3 copies of your main() function and your SCREEN_HEIGHT and SCREEN_WIDTH constants. Look in your project's "compile sources" build phase, you may have accidentally caused the .cpp source file end up there 3 times. \$\endgroup\$
    – uliwitness
    Commented Aug 5, 2018 at 15:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .