sdcc pic16 compiler linker

Help
tymop
2009-03-19
2013-03-12
  • tymop
    tymop
    2009-03-19

    Dear all,

    I made a post where I said I have a problem with the float. But The problem is other:
    I think the problem is between the c compiler and the linker (there is no problem when I call a function from a header in the test.c folder, but there is a problem when I call a function coming from the sdcc's headers) :
    I make a test.c file. This is the content:

    #include <string.h> 
    #include <pic18f252.h>

    char str1[10]; 

    void main(void) { 
    strcpy(str1, "testing"); 

    when I compile : no problem:
    `"C:\Program Files\SDCC\bin\sdcc.exe" test.c -c -mpic16 -p18F252`

    but when I call the linker : it does not work:
    `"C:\Program Files\SDCC\bin\sdcc.exe" "Z:\essai\test.o" -o"test.HEX" -mpic16 -p18F252`
    message: using default linker script "C:\Program Files\gputils\lkr\18f252.lkr"error: missing definition for symbol "_strcpy", required by "Z:\essai\test.o"

    So, what is the problem? How can I resolve it?
    I think the problem is the linker does not look at the folder with it's functions, but I don't know how I can say it to look at the good folder.

    Can anybody help me?

     
    • Raphael Neider
      Raphael Neider
      2009-03-19

      You need to link with the sdcc libraries (libsdcc.lib, libc18f.lib, lib18f252.lib). Try

      "C:\Program Files\SDCC\bin\sdcc.exe" -mpic16 -p18f252 -V test.c

      i.e., with -V to see how the compiler calls the linker and without -c to actually make sdcc link your project.

      Apart from that, the -L <dir> option to sdcc (or -I <dir> to gplink) adds <dir> to the linker's search path. Consult sdcc --help and/or gplink --help for more information.

      Good luck,
      Raphael

       
      • tymop
        tymop
        2009-03-19

        Firstly, thank for your help.
        I did what you said me, and this is the result:

        Executing: "C:\Program Files\SDCC\bin\sdcc.exe" test.c -c -mpic16 -p18F252 -I"Z:\GPS_Tracker\GPS_courseTracker\GPS_Embarque\Softs\TRIMBLE_decoder"Executing: "C:\Program Files\SDCC\bin\sdcc.exe"  "Z:\essai\test.o" -o"test.HEX" -mpic16 -p18F252 -Vmessage: using default linker script "C:\Program Files\gputils\lkr\18f252.lkr"error: missing definition for symbol "_strcpy", required by "Z:\essai\test.o"+ C:\PROGRA~1\gputils\bin\gplink.exe -I"C:\Program Files\SDCC\bin\..\lib\pic16"   -w -r -o test.HEX  Z:\essai\test.o  crt0i.o pic18f252.lib libsdcc.lib + C:\PROGRA~1\gputils\bin\gplink.exe -I"C:\Program Files\SDCC\bin\..\lib\pic16"   -w -r -o test.HEX  Z:\essai\test.o  crt0i.o pic18f252.lib libsdcc.lib  returned errorcode 1

         
        • Raphael Neider
          Raphael Neider
          2009-03-19

          I see, sdcc omits linking with libc18f.lib by default... Just append libc18f.lib (or -l libc18f.lib, they are treated identically) to your linker command line and you should be out of the woods.

          Best regards,
          Raphael

           
          • tymop
            tymop
            2009-03-20

            Thank you, it works well.