christobroa
New Member
- Total Posts : 30
- Reward points : 0
- Joined: 2011/05/30 09:05:22
- Location: 0
- Status: offline
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
|
ric
Super Member
- Total Posts : 24593
- Reward points : 0
- Joined: 2003/11/07 12:41:26
- Location: Australia, Melbourne
- Status: offline
Re: XC8 include problem with declaration of struct/function
2019/06/25 05:01:15
(permalink)
Try adding double quotes around the filenames #include "header.h" #include "functions.h"
To get a useful answer, always state which PIC you are using!
|
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)
I forgot to put " " in my description but not in my code, so this not the problem.
|
LdB_ECM
Senior Member
- Total Posts : 164
- Reward points : 0
- Joined: 2019/04/16 22:01:25
- Location: 0
- Status: online
Re: XC8 include problem with declaration of struct/function
2019/06/25 05:25:01
(permalink)
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.
|
ric
Super Member
- Total Posts : 24593
- Reward points : 0
- Joined: 2003/11/07 12:41:26
- Location: Australia, Melbourne
- Status: offline
Re: XC8 include problem with declaration of struct/function
2019/06/25 05:27:33
(permalink)
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)
To get a useful answer, always state which PIC you are using!
|
pcbbc
Super Member
- Total Posts : 1381
- Reward points : 0
- Joined: 2014/03/27 07:04:41
- Location: 0
- Status: online
Re: XC8 include problem with declaration of struct/function
2019/06/25 05:27:36
(permalink)
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.
|
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)
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.
|
ric
Super Member
- Total Posts : 24593
- Reward points : 0
- Joined: 2003/11/07 12:41:26
- Location: Australia, Melbourne
- Status: offline
Re: XC8 include problem with declaration of struct/function
2019/06/25 05:30:14
(permalink)
If you're not going to cooperate, it's pointless trying to help.
To get a useful answer, always state which PIC you are using!
|
pcbbc
Super Member
- Total Posts : 1381
- Reward points : 0
- Joined: 2014/03/27 07:04:41
- Location: 0
- Status: online
Re: XC8 include problem with declaration of struct/function
2019/06/25 05:33:32
(permalink)
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.
|
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)
|
pcbbc
Super Member
- Total Posts : 1381
- Reward points : 0
- Joined: 2014/03/27 07:04:41
- Location: 0
- Status: online
Re: XC8 include problem with declaration of struct/function
2019/06/25 05:51:02
(permalink)
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
|
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)
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.
|
ric
Super Member
- Total Posts : 24593
- Reward points : 0
- Joined: 2003/11/07 12:41:26
- Location: Australia, Melbourne
- Status: offline
Re: XC8 include problem with declaration of struct/function
2019/06/26 04:27:14
(permalink)
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.
To get a useful answer, always state which PIC you are using!
|