Multiple definition of 'some_object' error

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Multiple definition of 'some_object' error

      Hello everyone.

      When I try to add an existing or a new file (.h or .c) to the project, the compiler does not compile and turns with errors. My file structure is: .c files includes their .h files and those .h files are included by main.c. By the way header include guards are added.

      I am uploading an image that demonstrates my problem.

      Thank you all.
      Images
      • ss.png

        432.58 kB, 1,920×1,080, viewed 19 times
    • Your picture is not clear enough to read. Probably better to post the errors by copying & pasting the text.

      Whenever it gives you "Multiple definition" errors, it also tells you where all the definitions were found - so go and examine each one, and decide which to keep and which is erroneous.

      BTW: a common cause of "Multiple definition" errors is having variable definitions in header files - you should have only the declarations in the headers.

      c-faq.com/decl/decldef.html

      So-called include guards will not protect against this.
    • awneil wrote:

      Your picture is not clear enough to read. Probably better to post the errors by copying & pasting the text.

      Whenever it gives you "Multiple definition" errors, it also tells you where all the definitions were found - so go and examine each one, and decide which to keep and which is erroneous.

      BTW: a common cause of "Multiple definition" errors is having variable definitions in header files - you should have only the declarations in the headers.

      c-faq.com/decl/decldef.html

      So-called include guards will not protect against this.
      There are no definitions in my header files, only declerations; also there is no reason to have that error "multiple definition". I did not define anything again and again.
    • cann0021 wrote:

      there is no reason to have that error "multiple definition"
      Well, of course there is a reason - the tools don't just randomly make these things up for the fun of it!

      Again, the messages tell you where all the multiple definitions were found - so pursue that.

      As I said, your screenshot is unclear, but it looks like you might have the same file more than once in your project?
      Are you trying to combine two (or more) examples, where each example has its own definition of the functions in question ... ?