MPLAB X code compile error - Page 1
Forum section: electronics / general

author: Trabbo93
author_rank: Contributor
timestamp: July 12, 2013, 11:07:43 am
content: 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:make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-confmake: Entering directory `/Volumes/Emanuele/MPLABXProjects/LED BLINK.X'make -f nbproject/Makefile-default.mk dist/default/production/LED_BLINK.X.production.hexmake: 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 modeMicrochip MPLAB XC8 C Compiler V1.20Copyright (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: Leaving directory `/Volumes/Emanuele/MPLABXProjects/LED BLINK.X'make: Leaving directory `/Volumes/Emanuele/MPLABXProjects/LED BLINK.X'(908) exit status = 1make: *** [dist/default/production/LED_BLINK.X.production.hex] Error 1make: *** [.build-conf] Error 2make: *** [.build-impl] Error 2BUILD 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..

author: AndyC_772
author_rank: Super Contributor
timestamp: July 12, 2013, 11:11:33 am
content: 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?

author: Trabbo93
author_rank: Contributor
timestamp: July 12, 2013, 11:19:04 am
content: Code:#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

author: andersm
author_rank: Super Contributor
timestamp: July 12, 2013, 11:26:06 am
content: 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.

author: Trabbo93
author_rank: Contributor
timestamp: July 12, 2013, 11:41:11 am
content: Tried to make a new project without spaces in project name but I get same error..

author: ElektroQuark
author_rank: Unknown
timestamp: July 12, 2013, 11:53:50 am
content: Can you put a capture of the compilator paths screen?(Tools>Options>Embedded>Toolchain XC8)

author: Trabbo93
author_rank: Contributor
timestamp: July 12, 2013, 12:03:23 pm
content: this should be compiler path

author: ElektroQuark
author_rank: Unknown
timestamp: July 12, 2013, 12:13:20 pm
content: It looks like is OK

author: Trabbo93
author_rank: Contributor
timestamp: July 12, 2013, 01:06:13 pm
content: I'm trying to dowload MPLAB X for Windows and compile with that to see if is my mistake or compiler error..

author: veryevil
author_rank: Unknown
timestamp: July 12, 2013, 01:18:14 pm
content: try removing the plib from the include e.g.#include <plib/timers.h>to#include <timers.h>

author: Trabbo93
author_rank: Contributor
timestamp: July 12, 2013, 01:33:47 pm
content: Quote from: veryevil on July 12, 2013, 01:18:14 pmIDE doesn't find timers.h library at allwhat 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()

author: andersm
author_rank: Super Contributor
timestamp: July 12, 2013, 02:33:15 pm
content: 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.

author: Trabbo93
author_rank: Contributor
timestamp: July 12, 2013, 02:49:38 pm
content: Quote from: andersm on July 12, 2013, 02:33:15 pmSo how can I fix it? If the compiler PATHS are correct it should work..

author: TheDirty
author_rank: Frequent Contributor
timestamp: July 12, 2013, 03:03:56 pm
content: 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.

author: Trabbo93
author_rank: Contributor
timestamp: July 12, 2013, 03:20:58 pm
content: Quote from: TheDirty on July 12, 2013, 03:03:56 pmThe 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

author: TheDirty
author_rank: Frequent Contributor
timestamp: July 12, 2013, 05:52:52 pm
content: 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.

author: bxs
author_rank: Regular Contributor
timestamp: July 12, 2013, 06:06:00 pm
content: 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

author: Trabbo93
author_rank: Contributor
timestamp: July 12, 2013, 09:29:24 pm
content: Quote from: bxs on July 12, 2013, 06:06:00 pmThe 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- and64-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..

author: Trabbo93
author_rank: Contributor
timestamp: July 12, 2013, 09:59:27 pm
content: OK, rewritten code without libraries and it works fineWell 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

author: WarSim
author_rank: Frequent Contributor
timestamp: July 12, 2013, 10:33:35 pm
content: 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.

author: Volta500
author_rank: Contributor
timestamp: August 23, 2013, 07:38:39 am
content: 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.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: August 23, 2013, 08:33:25 am
content: Quote from: Volta500 on August 23, 2013, 07:38:39 amA 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.

author: dannyf
author_rank: Super Contributor
timestamp: September 06, 2013, 09:59:42 pm
content: "--chip=16F84"Is your plib supposed to work on 16F chips?

author: Rufus
author_rank: Super Contributor
timestamp: September 07, 2013, 12:52:36 am
content: Quote from: mikeselectricstuff on August 23, 2013, 08:33:25 amI 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.

author: dannyf
author_rank: Super Contributor
timestamp: September 08, 2013, 03:26:10 am
content: "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.

author: westfw
author_rank: Super Contributor
timestamp: September 08, 2013, 11:07:52 pm
content: QuoteYeah; in my mplab install, the library manual is pretty clearly titled "pic18_plib"...This is probably the spot where someone should say:DO NOT USE THE PIC16F84 ANY MORE !!!While there are a lot of hobbyist projects and tutorials that use this chip, that is mostly a consequence of it having been one of the first flash-based microcontrollers readily available to hobbyists, back in 1993. Since then, Microchip has released MANY newer chips that have more memory, more peripherals, more modern architectural features, that are CHEAPER as well. If you search at microchip, you'll find that the 16F84A is THE *most expensive* chip in an 18pin dip that they have. You can get one of their 16bit dspic30 chips for less!