Author Topic: Microchip XC8 compiler problems  (Read 12123 times)

0 Members and 1 Guest are viewing this topic.

Offline jwrodgersTopic starter

  • Supporter
  • ****
  • Posts: 39
Microchip XC8 compiler problems
« on: August 03, 2017, 10:05:37 pm »
Hi, just installed XC8, and I'm having problems when I try to include <xc.h>:

My main file:

Code: [Select]
/*
 * File:   newmain.c
 * Author:
 *
 * Created on August 3, 2017, 10:26 PM
 */

#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
/*
 *
 */
void main( void ) {

    return ( EXIT_SUCCESS );
}

And when I try and build it, I get the following error:

Code: [Select]
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory '/Users/mollyandchloe/Dropbox/MPLABXProjects/anotherCDelMe.X'
make  -f nbproject/Makefile-default.mk dist/default/production/anotherCDelMe.X.production.hex
make[2]: Entering directory '/Users/mollyandchloe/Dropbox/MPLABXProjects/anotherCDelMe.X'
"/Applications/microchip/xc8/v1.42/bin/xc8" --pass1  --chip=16LF18346 -Q -G  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -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,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled: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
make[2]: *** [build/default/production/newmain.p1] Error 1
/Applications/microchip/xc8/v1.42/include/xc.h:8: error: (102) #endif must be in an #if
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
(908) exit status = 1
nbproject/Makefile-default.mk:106: recipe for target 'build/default/production/newmain.p1' failed
make[2]: Leaving directory '/Users/mollyandchloe/Dropbox/MPLABXProjects/anotherCDelMe.X'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory '/Users/mollyandchloe/Dropbox/MPLABXProjects/anotherCDelMe.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 324ms)

And my xc.h file:

Code: [Select]
#ifndef _XC_H_
#define _XC_H_

#ifdef __XC8
#include <htc.h>
#endif

#endif //_XC_H

I am sure this is likely something very simple, but I've been trying for hours now and I'm not making any progress. Thanks for any help or pointers you can give me.
?
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12851
Re: Microchip XC8 compiler problems
« Reply #1 on: August 03, 2017, 10:46:48 pm »
C preprocessor errors tend to propagate for many lines and finally break the surface nowhere near their original cause.  Its probably not seeing the first #ifndef _XC_H_ line, due to a damaged stdio.h or stdlib.h file.    Comment out all the #includes except #include <xc.h> and see what happens.   You don't need them except for library functions that explicitly mention them on their page in the manual and #include <xc.h> should be first anyway.

If you've been careless viewing files in an editor you may have accidentally changed one - look at the modified dates of all the files in and below the XC8 include folder and see if any stand out.   If you cant locate the offending file and copy it from another machine with the same XC8 version, you may have to do a reinstall.

There may also be undesirable interactions between the Dropbox app and the XC8 compiler.  Try creating a new project in a folder that isn't synced by Dropbox.
« Last Edit: August 03, 2017, 10:53:50 pm by Ian.M »
 

Offline Andy Watson

  • Super Contributor
  • ***
  • Posts: 2082
Re: Microchip XC8 compiler problems
« Reply #2 on: August 03, 2017, 11:16:32 pm »
? ! 
Where did you get the make file from ?

Never mind. Go back to the start - keep it as simple as possible so that you can see where the errors are coming from. You should be able to compile "newmain.c" from the command line. E.g. :
xc8 --chip=16F1459 newmain.c
Substitute whatever processor you are using in place of the 16F1459. Bash down Correct all the errors that occur whilst learning how the compiler behaves. Now put what you have learnt into the make file - and onward...

I am not sure if this is an error, however, one problem is that your main program is declared as "void", but you try to return a value. The next problem, hypothetically assuming you get this code through the compiler, is where do you expect this program to "return" to ?

I have just tried to compile this:
Code: [Select]
void main(void)
{
   char x;
   
   while(1) {
      x++;   
   }
   return(0);
}
and the compiler throws an error at the return statement.


 

Offline jwrodgersTopic starter

  • Supporter
  • ****
  • Posts: 39
Re: Microchip XC8 compiler problems
« Reply #3 on: August 03, 2017, 11:46:07 pm »
Thanks for the ideas, I've tried commenting out the other includes, and reinstalled the compiler xc8, and creating a new project outside of the dropbox.

After this it still did not work.

I then tried the minimum code, and it worked. Created a new project, and added a new c main file (MPLAB IDE options) and got this file:

Code: [Select]

#include <xc.h>
#include <stdio.h>
#include <stdlib.h>


int main(int argc, char** argv) {

    return (EXIT_SUCCESS);
}


(This is from MPLAB, not sure where it would return that badboy to!) Anyway, it is compiling now ok:

Code: [Select]
CLEAN SUCCESSFUL (total time: 56ms)
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory '/Users/mollyandchloe/Dropbox/MPLABXProjects/FRDinC.X'
make  -f nbproject/Makefile-default.mk dist/default/production/FRDinC.X.production.hex
make[2]: Entering directory '/Users/mollyandchloe/Dropbox/MPLABXProjects/FRDinC.X'
"/Applications/microchip/xc8/v1.42/bin/xc8" --pass1  --chip=16LF18346 -Q -G  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -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,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/frdmain.p1  frdmain.c
"/Applications/microchip/xc8/v1.42/bin/xc8"  --chip=16LF18346 -G -mdist/default/production/FRDinC.X.production.map  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -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,-osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"      --memorysummary dist/default/production/memoryfile.xml -odist/default/production/FRDinC.X.production.elf  build/default/production/frdmain.p1     
Microchip MPLAB XC8 C Compiler (Free Mode) V1.42
Build date: Apr 12 2017
Part Support Version: 1.42
Copyright (C) 2017 Microchip Technology Inc.
License type: Node Configuration

:: warning: (1273) Omniscient Code Generation not available in Free mode

Memory Summary:
    Program space        used     7h (     7) of  4000h words   (  0.0%)
    Data space           used     6h (     6) of   800h bytes   (  0.3%)
    EEPROM space         used     0h (     0) of   100h bytes   (  0.0%)
    Data stack space     used     0h (     0) of   7F0h bytes   (  0.0%)
    Configuration bits   used     0h (     0) of     4h words   (  0.0%)
    ID Location space    used     0h (     0) of     4h bytes   (  0.0%)


You have compiled in FREE mode.
Using Omniscient Code Generation that is available in PRO mode,
you could have produced up to 60% smaller and 400% faster code.
See http://www.microchip.com/MPLABXCcompilers for more information.

make[2]: Leaving directory '/Users/mollyandchloe/Dropbox/MPLABXProjects/FRDinC.X'
make[1]: Leaving directory '/Users/mollyandchloe/Dropbox/MPLABXProjects/FRDinC.X'

BUILD SUCCESSFUL (total time: 1s)
Loading code from /Users/mollyandchloe/Dropbox/MPLABXProjects/FRDinC.X/dist/default/production/FRDinC.X.production.hex...
Loading completed


Not sure what happened! Thanks for the help.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12851
Re: Microchip XC8 compiler problems
« Reply #4 on: August 04, 2017, 12:03:50 am »
@Andy,
Looks like the O.P. is using the MPLAB X autogenerated default makefile: {ProjectFolder}/nbproject/Makefile-default.mk
Its unlikely to be a makefile error :-  /Applications/microchip/xc8/v1.42/bin/xc8.exe is barfing on the first pass of a release build near the end of /Applications/microchip/xc8/v1.42/include/xc.h, and the command line passed to it looks sane enough.

@J.W.R.
I'd put it down to MPLAB X weirdness - it gets a mite confused at times.
It can also interact very badly with virus scanners - its worth disabling realtime scanning on reads or execution for anything in or under /Applications/microchip by excluding the folder.  If possible leave scan on write enabled, and if not do a manual scan after any Micochip software installs or updates.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2536
  • Country: us
Re: Microchip XC8 compiler problems
« Reply #5 on: August 04, 2017, 01:23:47 am »
I think the key here is that the #include <xc.h> must be declared first before other system includes.
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: Microchip XC8 compiler problems
« Reply #6 on: August 04, 2017, 06:11:59 am »
There may also be undesirable interactions between the Dropbox app and the XC8 compiler.  Try creating a new project in a folder that isn't synced by Dropbox.

this is most likely to be your problem. i used to have the same problems (and more) with google drive, from time to time a new build would fail because it was still busy uploading the old files
« Last Edit: August 04, 2017, 06:13:55 am by JPortici »
 

Online cv007

  • Frequent Contributor
  • **
  • Posts: 824
Re: Microchip XC8 compiler problems
« Reply #7 on: August 04, 2017, 03:48:03 pm »
Quote
and got this file
That seems odd looking to me- this is what a newmain.c looks like for me-
#include <xc.h>

void main(void){
return;
}

(compiles without error)

Maybe in the new project 'wizard' you are going off the beaten path.
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: us
Re: Microchip XC8 compiler problems
« Reply #8 on: August 05, 2017, 12:49:16 am »
A void function (as shown in the earlier code) can not return a value.

ETA:  Embedded code never returns.  There is always a superloop

while(1) {
... your code goes here
}
 

Online cv007

  • Frequent Contributor
  • **
  • Posts: 824
Re: Microchip XC8 compiler problems
« Reply #9 on: August 05, 2017, 02:43:16 pm »
Quote
A void function (as shown in the earlier code) can not return a value.
...but it certainly can return. To where is up to the C runtime. In the case of XC8, you will end up with a jump back to 'start' (also generated by the C runtime). Why they don't put a while(1) in the generated code, I don't know. (I didn't make very clear- the newmain.c code shown was generated by MPLABX)

When I see generated code for a micro that has 'int main(int argc, char** argv)',  I would suspect something is not right. The 'generator' probably is thinking in 'pc' mode, and not microcontroller mode  for some reason.
« Last Edit: August 05, 2017, 02:46:47 pm by cv007 »
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: us
Re: Microchip XC8 compiler problems
« Reply #10 on: August 05, 2017, 10:50:36 pm »
Quote
A void function (as shown in the earlier code) can not return a value.
...but it certainly can return. To where is up to the C runtime. In the case of XC8, you will end up with a jump back to 'start' (also generated by the C runtime).

In the case of some early NXP ARMs (LPC2106, LPC2148), there is a one instruction spin loop immediately following the branch and link to main().  This is in the file crt.S, the startup file.  In this case, it is not provided by any part of the GCC code, it is a separate user generated assembly language file that deals with vectors, startup, and, ultimately, the branch and link to main().

If main happens to return, it will get stuck in the spin loop until the chip is reset.

I haven't looked at other processors because I make sure my code won't return.
 

Online cv007

  • Frequent Contributor
  • **
  • Posts: 824
Re: Microchip XC8 compiler problems
« Reply #11 on: August 06, 2017, 02:58:52 am »
I would suspect most C runtimes for micros simply spin in a loop if returned from main.

Of course, it would be odd to intentionally return from main in a microcontroller.  I guess if only using interrupt code one could return from main if you knew that the loop was there (but why). In the case of XC8, I would suspect their reasoning for jumping back to 'start' is to keep the micro running (a software reset would probably be preferred if the reset instruction was available).  So, it looks like XC8 considers a return from main as being a mistake, and yet MPLABX generated main code has a return in main. They seem a little conflicted.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf