• AVR Freaks

Hot!XC8 include problem with declaration of struct/function

Author
christobroa
New Member
  • Total Posts : 30
  • Reward points : 0
  • Joined: 2011/05/30 09:05:22
  • Location: 0
  • Status: offline
2019/06/25 04:53:56 (permalink)
0

XC8 include problem with declaration of struct/function

Hi,
I found myself confuse about #include
 

#ifndef XC_HEADER_TEMPLATE_H
#define XC_HEADER_TEMPLATE_
#include<stdint.h>
typedef struct{
uint8_t rien;
uint8_t nada;
}test_struct;
#endif /* XC_HEADER_TEMPLATE_H */

newxc8_header.h
 

#ifndef XC_HEADER_TEMPLATE_H
#define XC_HEADER_TEMPLATE_H
#include "newxc8_header.h"
uint8_t tintin(test_struct*);
#endif /* XC_HEADER_TEMPLATE_H */

functions.h
 

#include "functions.h"
uint8_t tintin(test_struct* data){
data->nada;
return data->rien+1;
}

functions.c
 

#include <xc.h>
#include"newxc8_header.h"
void main(void) 
    while(1)
    return;
}

main.c
result of compiling(part):
CLEAN SUCCESSFUL (total time: 313ms)
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'D:/BSRF-tempo/TEST/TEST.X'
make -f nbproject/Makefile-default.mk dist/default/production/TEST.X.production.hex
make[2]: Entering directory 'D:/BSRF-tempo/TEST/TEST.X'
"C:\Program Files (x86)\Microchip\xc8\v1.41\bin\xc8.exe" --pass1 --chip=18F65K22 -Q -G --double=24 --float=24 --emi=wordwrite -O0 --opt=+asm,-asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=pro -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,-plib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -obuild/default/production/newmain.p1 newmain.c
"C:\Program Files (x86)\Microchip\xc8\v1.41\bin\xc8.exe" --pass1 --chip=18F65K22 -Q -G --double=24 --float=24 --emi=wordwrite -O0 --opt=+asm,-asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=pro -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,-plib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -obuild/default/production/functions.p1 functions.c
make[2]: *** [build/default/production/functions.p1] Error 1
make[2]: *** Waiting for unfinished jobs....
functions.h:9: warning: (374) missing basic type; int assumed
functions.h:9: error: (372) "," expected
functions.h:9: error: (194) ")" expected
functions.h:9: warning: (349) non-prototyped function declaration for "tintin"
functions.h:9: error: (313) function body expected
functions.c:4: warning: (374) missing basic type; int assumed
functions.c:4: error: (372) "," expected
functions.c:4: error: (194) ")" expected
functions.c:5: error: (313) function body expected
functions.c:6: error: (285) no identifier in declaration
functions.c:6: warning: (374) missing basic type; int assumed
functions.c:6: error: (314) ";" expected
functions.c:7: error: (285) no identifier in declaration
functions.c:7: warning: (374) missing basic type; int assumed
functions.c:7: error: (314) ";" expected
(908) exit status = 1
nbproject/Makefile-default.mk:122: recipe for target 'build/default/production/functions.p1' failed
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory 'D:/BSRF-tempo/TEST/TEST.X'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory 'D:/BSRF-tempo/TEST/TEST.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 453ms)
So it doesn't do the link between declaration and body of function.
Now if I put the typdef in the functions.h >> it compile no problem.
 
Any ideas?
 
MPLABX IDE 5.05, XC8 V1.41.
 
 
 
 
 
post edited by christobroa - 2019/06/25 05:40:07
#1

12 Replies Related Threads

    ric
    Super Member
    • Total Posts : 22768
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: XC8 include problem with declaration of struct/function 2019/06/25 05:01:15 (permalink)
    0
    Try adding double quotes around the filenames
    #include "header.h"
     
    #include "functions.h"
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    christobroa
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2011/05/30 09:05:22
    • Location: 0
    • Status: offline
    Re: XC8 include problem with declaration of struct/function 2019/06/25 05:14:57 (permalink)
    0
    I forgot to put " " in my description but not in my code, so this not the problem.
     
    #3
    LdB_ECM
    Senior Member
    • Total Posts : 110
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: XC8 include problem with declaration of struct/function 2019/06/25 05:25:01 (permalink)
    0
    Likely you haven't got functions.c actually in your source code list because for some reason it isn't being compiled :-)
     
    It knows what it's looking for but can't find the code.
    #4
    ric
    Super Member
    • Total Posts : 22768
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: XC8 include problem with declaration of struct/function 2019/06/25 05:27:33 (permalink)
    0
    Better to cut this down to a minimal project the shows the problem, then post everything.
    We can't see what you are really doing when you are just retyping snippets of where you think the problem is (and making mistakes in the process)
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    pcbbc
    Super Member
    • Total Posts : 1108
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: XC8 include problem with declaration of struct/function 2019/06/25 05:27:36 (permalink)
    0
    christobroa
    I forgot to put " " in my description but not in my code, so this not the problem.

    Then what else did you "forget to put in"?  Because your code as posted (with quotes added as suggest by ric) compiles without error.
     
    Rememeber to put [​code]code tags[/​code] around you code when posting.
    #6
    christobroa
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2011/05/30 09:05:22
    • Location: 0
    • Status: offline
    Re: XC8 include problem with declaration of struct/function 2019/06/25 05:29:01 (permalink)
    0
    The thing is if I put the typedef in the functions.h intead of the header.h it's ok. So from my point of view it does'nt recognize te structure as a new type of variable.
    #7
    ric
    Super Member
    • Total Posts : 22768
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: XC8 include problem with declaration of struct/function 2019/06/25 05:30:14 (permalink)
    +1 (1)
    If you're not going to cooperate, it's pointless trying to help.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    pcbbc
    Super Member
    • Total Posts : 1108
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: XC8 include problem with declaration of struct/function 2019/06/25 05:33:32 (permalink)
    +2 (2)
    christobroa
    The thing is if I put the typedef in the functions.h intead of the header.h it's ok. So from my point of view it doesn't recognize te structure as a new type of variable.

    Stop making assumptions about what you think the problem is.  That's why you're here asking for help.
    #9
    christobroa
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2011/05/30 09:05:22
    • Location: 0
    • Status: offline
    Re: XC8 include problem with declaration of struct/function 2019/06/25 05:42:40 (permalink)
    0
    Updated post.
    #10
    pcbbc
    Super Member
    • Total Posts : 1108
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: XC8 include problem with declaration of struct/function 2019/06/25 05:51:02 (permalink)
    +3 (3)
    Read up on how...
    #ifndef XC_HEADER_TEMPLATE_H
    #define XC_HEADER_TEMPLATE_H
    ....
    #endif

    ...work.
     
    Every file you are going to include has to have a different #ifndef/#define name.
    If you use the same name in different files, then the second file you use it in will NOT be included.
     

        #ifndef NEWXC8_HEADER_H
        #define NEWXC8_HEADER_H
        #include<stdint.h>
        typedef struct{
        uint8_t rien;
        uint8_t nada;
        }test_struct;
        #endif /* NEWXC8_HEADER_H*/

        newxc8_header.h


        #ifndef FUNCTIONS_H
        #define FUNCTIONS_H
        #include "newxc8_header.h"
        uint8_t tintin(test_struct*);
        #endif /* FUNCTIONS_H*/

        functions.h
    post edited by pcbbc - 2019/06/25 05:54:31
    #11
    christobroa
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2011/05/30 09:05:22
    • Location: 0
    • Status: offline
    Re: XC8 include problem with declaration of struct/function 2019/06/26 04:24:56 (permalink)
    0
    You're right this was another mistake from my side.
    Finally I found some include "loop" that re-include header leading to issues:
    functions.h:9: error: (372) "," expected
    functions.h:9: error: (194) ")" expected
    functions.h:9: warning: (349) non-prototyped function declaration for "tintin"
    functions.h:9: error: (313) function body expected
     
    Thanks all.
    #12
    ric
    Super Member
    • Total Posts : 22768
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: XC8 include problem with declaration of struct/function 2019/06/26 04:27:14 (permalink)
    +1 (1)
    Personally, I never include header files into other header files, so I don't get loops.
    Still, it won't give errors when you implement the "include guards" correctly.
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #13
    Jump to:
    © 2019 APG vNext Commercial Version 4.5