This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem with GCC and string.h and stdlib

Note: This was originally posted on 8th October 2008 at http://forums.arm.com

Hi everyone,

i have following trouble with keil arm gnu compiler. i have recently moved to gnu and now i am having hard time to set it up.

description of problem: i am using real view arm compiler uvison3.5. i am using gnu chain tool set for aduc7021 (analog device) arm. when i tried to compile my code it gives me following errors:

"error: undefined reference to 'memcpy'
error: undefined reference to '_divsi3'
error: undefined reference to 'strcat'
error: undefined reference to 'memset'""

i tried to include string.h and stdlib.h in my project but it didn't help.


so if anybody can explain what is going on then it would be a great help.


thanks
nehal
  • Note: This was originally posted on 9th October 2008 at http://forums.arm.com

    thank you jacob.
    Problem solved. there was a option in linker script which was tell not to use standard library. so fixed that. thanks for the explanation.

    regards:
    nehal


    It appears that you haven't linked the standard libraries correctly.

    It's important to realize the difference between the compiler and the linker.

    • The compiler takes your source files and translates them into object files. Typically, these objects will include the assembly source and a number of symbols which the linker will use. The compiler doesn't know or care where resources (such as memcpy or __divsi3) exist, provided that they're declared in a header somewhere. Your C headers just tell the compiler "you can use this function, and here's its prototype".
    • The linker takes your object files and glues them all together. This generally entails resolving symbols to addresses and fitting your code into a memory structure. However, the headers you specified to the compiler mean nothing here; they just tell the compiler which symbols to add to the object file so the linker knows what to look for. The linker will search through all objects and any linked libraries for the symbols, and it will complain if it can't find them. That seems to be what's happening in your case.
    IDEs such as uVision often hide this relationship from the user, but it is important to understand.

    Having said that, the functions you listed are part of the standard C library, and as such they should be linked by default. You generally have to explicitly tell the linker to exclude the standard libraries, though it is common to exclude them for embedded targets and so your IDE may be configured to do that by default.

    I'm not familiar with uVision so I can't really help you with finding the correct options...
  • Note: This was originally posted on 9th October 2008 at http://forums.arm.com

    It appears that you haven't linked the standard libraries correctly.

    It's important to realize the difference between the compiler and the linker.

    • The compiler takes your source files and translates them into object files. Typically, these objects will include the assembly source and a number of symbols which the linker will use. The compiler doesn't know or care where resources (such as memcpy or __divsi3) exist, provided that they're declared in a header somewhere. Your C headers just tell the compiler "you can use this function, and here's its prototype".
    • The linker takes your object files and glues them all together. This generally entails resolving symbols to addresses and fitting your code into a memory structure. However, the headers you specified to the compiler mean nothing here; they just tell the compiler which symbols to add to the object file so the linker knows what to look for. The linker will search through all objects and any linked libraries for the symbols, and it will complain if it can't find them. That seems to be what's happening in your case.
    IDEs such as uVision often hide this relationship from the user, but it is important to understand.

    Having said that, the functions you listed are part of the standard C library, and as such they should be linked by default. You generally have to explicitly tell the linker to exclude the standard libraries, though it is common to exclude them for embedded targets and so your IDE may be configured to do that by default.

    I'm not familiar with uVision so I can't really help you with finding the correct options...