Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

trouble with link

cloudyyue
2011-06-04
2013-03-12
  • cloudyyue
    cloudyyue
    2011-06-04

    I want to compile a progrom with two C files.
    main.c and part.c.
    I find errors until I click link.
    It report:
    Link in progress…
    c:\Program Files\SDCC\BIN\SDCC.EXE  -debug -use-stdout -V  -I"F:\sdcc test" -o"F:\sdcc test\test.hex" "F:\sdcc test\main.rel" 

    ?ASlink-Warning-Undefined Global '_Port_IO_Init' referenced by module 'main'

    ?ASlink-Warning-Undefined Global '_Oscillator_Init' referenced by module 'main'
    + c:\PROGRA~1\SDCC\BIN\sdld.exe -nf "F:\sdcc test\test.lnk"
    + c:\PROGRA~1\SDCC\BIN\sdld.exe -nf "F:\sdcc test\test.lnk" returned errorcode 4

    the following is the code
    main.c:

    #include "part.h"

    void Init_Device(void)
    {
        Port_IO_Init();
        Oscillator_Init();
    }

    void main()
    {
    Init_Device();
    }

    part.c:

    #include "C8051F020.h"

    void Port_IO_Init()
    {
        P0MDOUT   = 0x40;
        XBR2      = 0x40;
    }

    void Oscillator_Init()
    {
        OSCICN    = 0x07;
    }

    Why the linkage cant find the functions?
    every help is appreciated!

     
  • cloudyyue
    cloudyyue
    2011-06-04

    Additionally

    part.h:

    #include "C8051F020.h"

    void Port_IO_Init();

    void Oscillator_Init();

     
  • wis3m0nkey
    wis3m0nkey
    2011-06-06

    I don't know solution yet but I've exactly same issue and as much as I searched I couldn't find solution

     
  • cloudyyue
    cloudyyue
    2011-06-06

    Thank you all the same!

    Let's wait for the an answer

     

  • Anonymous
    2011-06-06

    The clue is in the the output you posted:

    c:\Program Files\SDCC\BIN\SDCC.EXE  --debug --use-stdout -V  -I"F:\sdcc test" -o"F:\sdcc test\test.hex" "F:\sdcc test\main.rel"
    

    The .rel files are the objects to be linked together. You only have main.rel in there, whereas it needs both main.rel and part.rel.

    Hope that helps.

     
  • wis3m0nkey
    wis3m0nkey
    2011-06-06

    Hi Thank you for your opinion, however now I received warning:

    ASlink-Warning-No definition of area HOME
    

    I'll try making plain header files instead of multiple c files and let you know

     
  • wis3m0nkey
    wis3m0nkey
    2011-06-06

    Ok so before my structure of program was:
    main
      header files

    and
      header files -> respective C files

    However when I renamed .c files to .h files and tried compiling it worked properly though even now I've one warning remaining:

    ?ASlink-Warning-Undefined Global '_main_bAckReturned_1_1' referenced by module 'test'

    bAckReturned is of type bit and declared in main module itself (collects acknowledgements)

    Any thoughts?

     
  • wis3m0nkey
    wis3m0nkey
    2011-06-06

    cloudyyue: I can compile your program successfully if I rename part.c to part.h (I know not a good way to do it but it works).
    I didn't test it for functionality or anything, just compiled.

     
  • Maarten Brock
    Maarten Brock
    2011-06-07

    Are you by any chance using the SiLabs IDE for building? I guess you are and wonder why you didn't tell.

    In the IDE you must add all .c files to the list of files to be compiled and all the resulting .rel files to the list of files to be linked. This can be done through the menu "Project / Target Build Configuration / Customize" or you can right click the source files and choose "Add … to build".

     
  • wis3m0nkey
    wis3m0nkey
    2011-06-07

    I don't know about cloudyyue, however I'm not using any IDE (was using mcu8051 opensource IDE but will switch to it once I get command line working).
    Moreover currently I've issue with variable declared in top module itself.
    I may try making it of type unsigned char instead of bit.

     
  • You don't seem to have grasped Phil's point. You need to include 'part.rel' in the link command line. From the command line try typing:
    c:\Program Files\SDCC\BIN\SDCC.EXE -debug -use-stdout -V -I"F:\sdcc test" -o"F:\sdcc test\test.hex" "F:\sdcc test\main.rel"  "F:\sdcc test\part.rel"

     
  • wis3m0nkey
    wis3m0nkey
    2011-06-08

    You don't seem to have grasped Phil's point. You need to include 'part.rel' in the link command line. From the command line try typing: c:\Program Files\SDCC\BIN\SDCC.EXE -debug -use-stdout -V -I"F:\sdcc test" -o"F:\sdcc test\test.hex" "F:\sdcc test\main.rel" "F:\sdcc test\part.rel"

    hi oliver if u were telling me then I used this command itself,however I'm on linux so used ./part.rel instead of complete path if that makes any difference and without quotation marks.

    As for my issue as I said I changed data type from bit to unsigned char for that particular variable and its fixed

    So the question is:
    Does sdcc support bit type data? Documentation (online doc) says it does..

     
  • You don't say which directory you are executing the link command from, so I can't tell whether ./part.rel is the same as "F:\sdcc test\part.rel". Quotes are needed if the file name includes spaces.

    As for your comment about bit types, I'm assuming this is a digression. SDCC supports bit types, but you haven't shown that in the code you've posted.

     
  • wis3m0nkey
    wis3m0nkey
    2011-06-08

    You don't say which directory you are executing the link command from, so I can't tell whether ./part.rel is the same as "F:\sdcc test\part.rel". Quotes are needed if the file name includes spaces.

    My working directory contains all .c / .h and hence all .rel files are in same directory moreover I don't have spaces in file name so I can use ./ safely.

    As for your comment about bit types, I'm assuming this is a digression. SDCC supports bit types, but you haven't shown that in the code you've posted.

    Now that I think of it, the issue maybe because of

     #define bit bool
    typedef uInt1 bool
    

    I'll try

    typedef uInt1 bit
    

    tonight and let you guys know.

    Ohh I used bool out of habit and then read that SDCC supports only bit so instead on changing all I tried define

     
  • wis3m0nkey
    wis3m0nkey
    2011-06-09

    ok so:

    typedef bit         uInt1;
    uInt1 bAckReturned;
    

    provides with an error:

    ?ASlink-Warning-Undefined Global '_main_bAckReturned_1_1' referenced by module 'test'

    If I change code to

    bit bAckReturned;
    

    I get same error:

    ?ASlink-Warning-Undefined Global '_main_bAckReturned_1_1' referenced by module 'test'

    However when code is:

    typedef unsigned char       uInt8;
    uInt8 bAckReturned;
    

    code compiles perfectly. Thats why I asked about support for bit..
    Unless I'm misunderstanding/over looking something

     
  • wis3m0nkey
    wis3m0nkey
    2011-06-17

    ok so I had issues with wrong externs, fixed them and now design passes successfully through keil but not through SDCC.

    The way I'm compiling is - only one top file, My guess is I need to have all c files in command? or compile and link them ?
    right now here is how I'm doing it

    #include "file1.h"
    #include "file2.h"
    //main code
    
    sdcc -mmcs51 --iram-size 128 --xram-size 0 --code-size 4096  --nooverlay --noinduction --verbose --debug -V --std-sdcc99 --model-small --pack-iram  main.c
    

    Do I need to compile and use file1.rel and file2.rel somehow?

     
  • Maarten Brock
    Maarten Brock
    2011-06-17

    If you put everything in main.c you will not get any file1.rel and file2.rel so there is no way to link them, is there?
    And since you do not use the -compile-only flag (-c) SDCC will link the one main.rel immediately after compilation.

    When you say it doesn't pass successfully through SDCC shouldn't you give some info on how it fails? Did you happen to get any errors or warnings? And if so, what are they? And what code is causing them? I'm sure it's not the 3 lines you showed.