Author Topic: MPLAB X code compile error  (Read 28694 times)

0 Members and 2 Guests are viewing this topic.

Offline Trabbo93

  • Contributor
  • Posts: 11
MPLAB X code compile error
« on: July 12, 2013, 11:07:43 am »
Hi, i'm an italian automation engineering student at 1st year of studies. I've just bought a PICkit3 to start mocking around with somethig different from Arduino or Cubloc controllers but after only 10 min of led blinking program develop i'm blocked by a stupid compiler error..

Code: [Select]
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/Volumes/Emanuele/MPLABXProjects/LED BLINK.X'
make  -f nbproject/Makefile-default.mk dist/default/production/LED_BLINK.X.production.hex
make[2]: Entering directory `/Volumes/Emanuele/MPLABXProjects/LED BLINK.X'
"/Applications/microchip/xc8/v1.20/bin/xc8" --pass1  --chip=16F84 -Q -G  --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --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 "--errformat=%f:%l: error: %s" "--warnformat=%f:%l: warning: %s" "--msgformat=%f:%l: advisory: %s"  -obuild/default/production/newmain.p1  newmain.c
"/Applications/microchip/xc8/v1.20/bin/xc8"  --chip=16F84 -G -mdist/default/production/LED_BLINK.X.production.map  --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --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 "--errformat=%f:%l: error: %s" "--warnformat=%f:%l: warning: %s" "--msgformat=%f:%l: advisory: %s"   -odist/default/production/LED_BLINK.X.production.elf  build/default/production/newmain.p1     
:: warning: Omniscient Code Generation not available in Free mode
Microchip MPLAB XC8 C Compiler V1.20
Copyright (C) 2013 Microchip Technology Inc.
License type: Node Configuration

:0: error: undefined symbols:
        _ReadTimer0(dist/default/production/LED_BLINK.X.production.obj) _OpenTimer0(dist/default/production/LED_BLINK.X.production.obj) _WriteTimer0(dist/default/production/LED_BLINK.X.production.obj)
make[2]: Leaving directory `/Volumes/Emanuele/MPLABXProjects/LED BLINK.X'
make[1]: Leaving directory `/Volumes/Emanuele/MPLABXProjects/LED BLINK.X'
(908) exit status = 1
make[2]: *** [dist/default/production/LED_BLINK.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

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

obviously in my code i've included /plib/timers.h and the IDE doesn't put the "red dot" near the lines where i use OpenTimer0() or ReadTimer0()
but i get this error.. can anyone help me?

MPLAB X is running under MAC OSX 10.7.5 with XC8 compiler..

thanks and sorry for bad bad english.. |O
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 3496
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: MPLAB X code compile error
« Reply #1 on: July 12, 2013, 11:11:33 am »
Hi,

You need to post your code if you want anyone to be able to spot what's wrong!

Do you have #include <xc.h> at the start of your code?

Offline Trabbo93

  • Contributor
  • Posts: 11
Re: MPLAB X code compile error
« Reply #2 on: July 12, 2013, 11:19:04 am »
Code: [Select]
#include <xc.h>
#include <plib/timers.h>

#define _XTAL_FREQ 80000
#pragma config FOSC = EXTRC     // Oscillator Selection bits (RC oscillator)
#pragma config WDTE = OFF       // Watchdog Timer (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (Power-up Timer is disabled)
#pragma config CP = OFF         // Code Protection bit (Code protection disabled)


void main() {
    unsigned char TM0Config;
    unsigned char time = 0;
    TM0Config = T0_8BIT & T0_PS_1_256 & TIMER_INT_ON & T0_SOURCE_INT;

    OpenTimer0(TM0Config);
   
    TRISA = 0;
    RA0 = 0;
    TRISB = 0;
    PORTB = 0;

   WriteTimer0(0x20);
   TMR0IF=0;
   ei();
   
    while (1){
        time=ReadTimer0();
        PORTB=time;
    }

}

void interrupt TimerOverflow()
{
    if(TMR0IF == 1)
    {
        RA0 = ~RA0;
        TMR0IF = 0;
        WriteTimer0(0x20);
    }

}
here is my code  ;D
 

Online andersm

  • Super Contributor
  • ***
  • Posts: 1075
  • Country: fi
Re: MPLAB X code compile error
« Reply #3 on: July 12, 2013, 11:26:06 am »
Note that you should avoid using paths and file names with spaces in them. The GNU Make tool used for building can have problems with them.

Offline Trabbo93

  • Contributor
  • Posts: 11
Re: MPLAB X code compile error
« Reply #4 on: July 12, 2013, 11:41:11 am »
Tried to make a new project without spaces in project name but I get same error..
 

Offline ElektroQuark

  • Supporter
  • ****
  • Posts: 1217
  • Country: es
    • ElektroQuark
Re: MPLAB X code compile error
« Reply #5 on: July 12, 2013, 11:53:50 am »
Can you put a capture of the compilator paths screen?
(Tools>Options>Embedded>Toolchain XC8)

Offline Trabbo93

  • Contributor
  • Posts: 11
Re: MPLAB X code compile error
« Reply #6 on: July 12, 2013, 12:03:23 pm »
this should be compiler path
 

Offline ElektroQuark

  • Supporter
  • ****
  • Posts: 1217
  • Country: es
    • ElektroQuark
Re: MPLAB X code compile error
« Reply #7 on: July 12, 2013, 12:13:20 pm »
It looks like is OK

Offline Trabbo93

  • Contributor
  • Posts: 11
Re: MPLAB X code compile error
« Reply #8 on: July 12, 2013, 01:06:13 pm »
I'm trying to dowload MPLAB X for Windows and compile with that to see if is my mistake or compiler error..
 

Offline veryevil

  • Supporter
  • ****
  • Posts: 196
  • Country: gb
Re: MPLAB X code compile error
« Reply #9 on: July 12, 2013, 01:18:14 pm »
try removing the plib from the include e.g.

#include <plib/timers.h>

to

#include <timers.h>
 

Offline Trabbo93

  • Contributor
  • Posts: 11
Re: MPLAB X code compile error
« Reply #10 on: July 12, 2013, 01:33:47 pm »
try removing the plib from the include e.g.

#include <plib/timers.h>

to

#include <timers.h>

IDE doesn't find timers.h library at all

what that looks me strange is that in the compiler error message the function OpenTimer0() which is correcly recognized by MPLAB, for example, is named _OpenTimer0()
 

Online andersm

  • Super Contributor
  • ***
  • Posts: 1075
  • Country: fi
Re: MPLAB X code compile error
« Reply #11 on: July 12, 2013, 02:33:15 pm »
The C compiler automatically adds a leading underscore to symbols. If you see the underscore in an error message it's a telltale sign it's a linking error, not a compilation error.

Offline Trabbo93

  • Contributor
  • Posts: 11
Re: MPLAB X code compile error
« Reply #12 on: July 12, 2013, 02:49:38 pm »
The C compiler automatically adds a leading underscore to symbols. If you see the underscore in an error message it's a telltale sign it's a linking error, not a compilation error.
So how can I fix it? If the compiler PATHS are correct it should work..
 

Offline TheDirty

  • Frequent Contributor
  • **
  • Posts: 440
  • Country: ca
Re: MPLAB X code compile error
« Reply #13 on: July 12, 2013, 03:03:56 pm »
What's your new error message?

I had to uninstall and reinstall mplabx and xc8 into a c:\microchip directory for it to work.  It does not like the 'Program Files' directory name.
Mark Higgins
 

Offline Trabbo93

  • Contributor
  • Posts: 11
Re: MPLAB X code compile error
« Reply #14 on: July 12, 2013, 03:20:58 pm »
What's your new error message?

I had to uninstall and reinstall mplabx and xc8 into a c:\microchip directory for it to work.  It does not like the 'Program Files' directory name.

The error message is still the same i posted before.. it seems seeing the library but don't link correcty..
I'll try to reinstall in another directory.. ;)

EDIT: Reinstalled in /microchip and.... same error again |O |O |O
« Last Edit: July 12, 2013, 03:38:20 pm by Trabbo93 »
 

Offline TheDirty

  • Frequent Contributor
  • **
  • Posts: 440
  • Country: ca
Re: MPLAB X code compile error
« Reply #15 on: July 12, 2013, 05:52:52 pm »
Sorry, I just skimmed this before.

I've never used these macros so I tried to look it up in help.  Your 0 functions don't look like they exist.  I see a readtimer1 and a writetimer1 thru 5, but no readtimer0 or writetimer0.

EDIT:  Hmmm just checked timers.h and the function is primed in there.  So I'm not sure.
« Last Edit: July 12, 2013, 05:58:05 pm by TheDirty »
Mark Higgins
 

Offline bxs

  • Regular Contributor
  • *
  • Posts: 89
  • Country: 00
Re: MPLAB X code compile error
« Reply #16 on: July 12, 2013, 06:06:00 pm »
I don't use microchip for some time, but if it didn't changed the problem is really simple.

Note that you are using a PIC16F84, so far so good, the problem is with plib, at least at older versions of XC8 plibs only support PIC18F parts ;-)

For 10/12/16 series you will have to write your libs  :-DD
 

Offline Trabbo93

  • Contributor
  • Posts: 11
Re: MPLAB X code compile error
« Reply #17 on: July 12, 2013, 09:29:24 pm »
I don't use microchip for some time, but if it didn't changed the problem is really simple.

Note that you are using a PIC16F84, so far so good, the problem is with plib, at least at older versions of XC8 plibs only support PIC18F parts ;-)

For 10/12/16 series you will have to write your libs  :-DD

The MPLAB
®
XC8 C Compiler is a free-standing, optimizing ANSI C compiler. It sup-
ports all 8-bit PIC
®
microcontrollers: PIC10, PIC12, PIC16 and PIC18 series devices,
as well as the PIC14000 device.
The compiler is available for several popular operating systems, including 32- and
64-bit Windows
®
, Linux and Apple OS X.

This is what I read on XC8 compiler manual so I supposed that all libs included in the compiler where compatible with pic16.. ok that's a problem..
« Last Edit: July 12, 2013, 09:44:32 pm by Trabbo93 »
 

Offline Trabbo93

  • Contributor
  • Posts: 11
Re: MPLAB X code compile error
« Reply #18 on: July 12, 2013, 09:59:27 pm »
OK, rewritten code without libraries and it works fine  :)
Well for my little newbie projects I could use registers manually.. in case I will buy some 18F parts for future projects well to know that plibs will work without errors..
thank you all  ;)
 

Offline WarSim

  • Frequent Contributor
  • **
  • Posts: 514
MPLAB X code compile error
« Reply #19 on: July 12, 2013, 10:33:35 pm »
The new naming conventions for microchip seems to be timers 1-n. 
It would have been interesting to see if the library would work as Timer1. 
 

Offline Volta500

  • Contributor
  • Posts: 18
  • Country: nl
Re: MPLAB X code compile error
« Reply #20 on: August 23, 2013, 07:38:39 am »
Why would you use libraries for simple functions like a timer? Unless you know exactly what the lib is doing you are only asking for trouble. Much easier and quicker to just set the regs manually + that you know what is happening in your program. Personally I only use libs for things that are way too much work to do manually like Ethernet, USB and the like. And read the notes for that lib and through the source.
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 12042
  • Country: gb
    • Mike's Electric Stuff
Re: MPLAB X code compile error
« Reply #21 on: August 23, 2013, 08:33:25 am »
Why would you use libraries for simple functions like a timer? Unless you know exactly what the lib is doing you are only asking for trouble. Much easier and quicker to just set the regs manually + that you know what is happening in your program. Personally I only use libs for things that are way too much work to do manually like Ethernet, USB and the like. And read the notes for that lib and through the source.
A lot of MCU manufacturers seem to be jumping on the bandwagon of offering libraries for even the simplest functions, even those where it would be quicker to code your own than look up all the bits you need to use the library function.
The problem I have is that often it just changes the process of learning the chip to that of learning the libraries (along with gazillions of constants for all the options & parameters), and figure out their limitations and quirks, and then have to learn the chip anyway when you need to either do something the library doesn't support or track down bugs in the library.
Seems pretty pointless to me in a lot of cases.

Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: MPLAB X code compile error
« Reply #22 on: September 06, 2013, 09:59:42 pm »
"--chip=16F84"

Is your plib supposed to work on 16F chips?
================================
https://dannyelectronics.wordpress.com/
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2094
Re: MPLAB X code compile error
« Reply #23 on: September 07, 2013, 12:52:36 am »
A lot of MCU manufacturers seem to be jumping on the bandwagon of offering libraries for even the simplest functions, even those where it would be quicker to code your own than look up all the bits you need to use the library function.

I think the idea is that it makes the code more portable between processors and families. Microchip are also trying to make their XC compilers more compatible with what they call their Common C Interface.

I don't think it really works or is very useful. Microchip are the only people trying to make the same code run on a zillion different processors from 3 families on various boards for all their application and hardware demos. The code is so riddled with #ifdefs and complex file structures and conditional includes that porting it to your custom hardware is actually made more difficult.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: MPLAB X code compile error
« Reply #24 on: September 08, 2013, 03:26:10 am »
"Common C Interface. "

CCI is more about coding style than anything else.

"I don't think it really works or is very useful. "

It depends. For simple chips (like a PIC or AVR), or chips with very diverse peripheral sets (PIC for example), it is more pain to work through an OEM library that covers a wide range of chips, than to work with the chips in question directly.

But coding through a well defined framework is always a plus as it allows reuse of previously coded pieces -> faster development cycle, better reliability, and lower costs / headache.

More so for more complex chips.
================================
https://dannyelectronics.wordpress.com/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf