Friday, April 29, 2011

Microchip Linker problem

hello guys,when i was trying to build my project in MPLAB,i got this Build error message..

    Clean: Deleting intermediary and output files.
Clean: Deleted file "M:\12 CCP PWM\12 CCP PWM.o".
Clean: Done.
Executing: "C:\MCC18\bin\mcc18.exe" -p=18F46K20 "12 CCP PWM.c" -fo="12 CCP PWM.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
MPLAB C18 v3.20 (feature limited)
Copyright 1999-2005 Microchip Technology Inc.
This version of MPLAB C18 does not support the extended mode
and will not perform all optimizations.  To purchase a full
copy of MPLAB C18, please contact your local distributor or
visit buy.microchip.com.

Executing: "C:\MCC18\bin\mplink.exe" /l"C:\MCC18\lib" "C:\MCC18\lkr\18f46k20i.lkr" "12 CCP PWM.o" /u_CRUNTIME /o"12 CCP PWM.cof" /M"12 CCP PWM.map" /W
MPLINK 4.20, Linker
Copyright (c) 2008 Microchip Technology Inc.
Error - could not find definition of symbol 'main' in file 'C:\MCC18\lib/c018i.o'.
Errors    : 1

Link step failed.
----------------------------------------------------------------------
Release build of project `M:\12 CCP PWM\12 CCP PWM.mcp' failed.
Thu Apr 16 14:34:41 2009
----------------------------------------------------------------------
BUILD FAILED

I have checked that the path to the linker library was correct.I suspect it has something to do with my source code...Any helps are very much appreciated.

Here is my source code.. http://cl1p.net/mplabc18

From stackoverflow
  • Personally I would not strain the corners of the implementation by having source file names with several spaces in, particularly with an embedded toolchain!

    But it seems like they're making a reasonable effort to add all the double-quotes, so maybe that's not a real problem.

    Do you actually have a 'main' function in your code, and if so, exactly how is it defined?

  • I use a third-party compiler, so I can't offer any specific experience on that. But one thing I may suspect is that something in the code is causing the compilation to stop partway through. This can be an unterminated comment, or a function with a closing brace missing. Consider especially the #included files, because you can't see the effects in your editor when you look at the main file, and particularly check any #includes that you have written yourself. And at the top of the list is, "what did you change last"?

    What I do at this point is make a branch copy, and start mercilessly hacking out huge blocks of code, just to see when the error goes away. Divide and conquer. Of course, this can be time consuming, so I'd probably ask on StackOverflow, first :)

  • It's been a while, but I saw that you used a pragma to define the location of the interrupt handler before you created the function, might you need to do the same thing with main()?

    It might be handled in the .h file - I'm not sure. I only ever used ASM on the PICs and I explicitly handled everything (ie, at 0x000 jump to main; at the interrupt vector address jump to this memory address; at main address do these things, etc). 'main' for me was defined to be an available address in the code section (which I see you've done, started the code section then defined main) but I believe I had to explicitly define that 'main' was to start at a memory address in the code section. Again, it was ASM, but I wouldn't doubt that you need to do something similar - a pragma to define main as main.

  • If c018i.o contains the reset vector, and it refers to the function main by name, then the issue could be that main needs a prototype - even in the same file as the function itself, so the linker can pick this up and put main in its list of functions.

    So, try inserting:

    void main (void);
    

    immediately above the main function.

    twiart : didn't work either :(
  • The compiler may be looking for a different definition of main. I have seen this in some PIC code:

    // Main application entry point.
    #ifdef __C30__
    int main(void)
    #else
    void main(void)
    #endif
    { ... }
    
    twiart : i have tried it.still the same :(
  • The only thing that stood out to me in your source file is this part of the ISR declaration:

    #pragma code InterruptVectorLow = 0x18

    The user guide of the compiler you're using states this should be:

    #pragma code low_vector=0x18

    Since this declaration is just before your main function it might be giving you trouble.

    Edit:

    None of the presented solutions seem to work so I have just copy-pasted your code into a new MPLAB project, set up for the PIC18F46K20 device. It compiles just fine with the MCC18 compiler. The only thing that's missing from the project is the "12 CCP PWM.h" header file (which I do not have). So either there's something wrong with your header file, there's something wrong with your project setup, or the fact that I'm using MCC18 3.30 instead of 3.20 is the problem.

    twiart : didn't work either :(
  • It is a good idea to add the specific linker file to your project. If you are using MPLAB, under the workspace, right click on linker files and add the linker file from mcc16\lkr folder for the specific processor. Clean and Re-compile the solution

    twiart : I have added it.still the same..
  • code compiles fine for me (C18 3.30 full)

    i've had MPLAB flake out a bit on me especially on large source trees, many times a reboot has solved it, absolutely no idea why, tried everything else and it was the only way to get mplab to reset.

    Jeanne Pindar : +1 That sometimes MPLAB just gets confused and needs to be restarted.

0 comments:

Post a Comment