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
  • "no error if compiled in C compiler."

    Well, of course there isn't: you can only get Linker errors from the Linker!!

    See my reply here:
    http://www.keil.com/forum/docs/thread1812.asp

    Your file struct.h contains a definition of i; presumably you are also #includeing it in another 'C' source file (struct.c?) so that file will also contain a definition of i - presto! multiple definitions!

    You need to define i in one file only (eg, main.c) and then just have an extern declaration in your header file.

    BTW: 'i' is a particularly bad name for a global variable!

Reply
  • "no error if compiled in C compiler."

    Well, of course there isn't: you can only get Linker errors from the Linker!!

    See my reply here:
    http://www.keil.com/forum/docs/thread1812.asp

    Your file struct.h contains a definition of i; presumably you are also #includeing it in another 'C' source file (struct.c?) so that file will also contain a definition of i - presto! multiple definitions!

    You need to define i in one file only (eg, main.c) and then just have an extern declaration in your header file.

    BTW: 'i' is a particularly bad name for a global variable!

Children