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

What's wrong with the define of STRUCT?

Hello all,
My project with 3 files as following ,the MAIN is in sys.c,all 3 files are compiled well each other.
File a: including sys.c and common.h
File b: including rtk.c and rtk.h
File c: including blt.c and blt.h

rtk.h:
...
extern uchar code rtk_Cmd[20]={...};
extern struct Time
{uchar Sec;...};
extern struct Date
{...};
extern struct Time sGps;
...

rtk.c:
#include <rtk.h>
...

syc.c:
#include <common.h>
#include <rtk.h>
#include <blt.h>
....
void main()
{
...
Func1(sGps.Sec);
Func2(rtk_Cmd);
...
}


when build all files, the error L104:mutiple public defintion (rtk_cmd)
Warning L1: unresolved external symbol(sGps).
Give me your hands ,thanks a lot!

Parents
  • In this way,all files can be build ,is it right?

    It may work, but it's not right.

    As a rule of thumb: never write 'extern' in a .c file --- it only ever should appear in .h files.

    In your case, this line:

    extern struct MesInfo GpsInfo;
    really belongs into rtk.h, because that's the interface description for rtk.c, and GpsInfo is part of the published interface of rtk.c.

Reply
  • In this way,all files can be build ,is it right?

    It may work, but it's not right.

    As a rule of thumb: never write 'extern' in a .c file --- it only ever should appear in .h files.

    In your case, this line:

    extern struct MesInfo GpsInfo;
    really belongs into rtk.h, because that's the interface description for rtk.c, and GpsInfo is part of the published interface of rtk.c.

Children
No data