This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS

struct.h:

#ifndef _STRUCT_H
#define _STRUCT_H

int i;

#endif

main.c:
#include "struct.h"
void main(void)
{
	i = 1;
}

when compiled and linked,error is showed as follow:

Build target 'Target 1'
compiling main.c...
linking...
*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS
SYMBOL: I
MODULE: struct.obj (STRUCT)
Program Size: data=9.0 xdata=4 code=16
Target not created

What is the problem?
Note:no error if compiled in C compiler.

Parents
  • You can include a header file which declares an identifier in the source file which defines that identifier; eg,

    /* Foo.h */
    #ifndef FOO_H_INCLUDED
    #define FOO_H_INCLUDED
    
    extern int foo_var;
    
    #endif /* FOO_H_INCLUDED */
    
    
    /* Foo.c */
    #include "Foo.h"
    
    int foo_var;
    The advantage to doing this is that the compiler can warn you if the declaration doesn't match the definition

Reply
  • You can include a header file which declares an identifier in the source file which defines that identifier; eg,

    /* Foo.h */
    #ifndef FOO_H_INCLUDED
    #define FOO_H_INCLUDED
    
    extern int foo_var;
    
    #endif /* FOO_H_INCLUDED */
    
    
    /* Foo.c */
    #include "Foo.h"
    
    int foo_var;
    The advantage to doing this is that the compiler can warn you if the declaration doesn't match the definition

Children
No data