embeddedlinker-errorselfsystemcsystem-on-chip

Difficulty in using C standard libraries in the SoCLib tool


I'm an electronic engineering student from Brazil and I'm currently working with embedded systems.

I'm trying to port a MP3 decoder (written in C), called minimp3, to a platform built with the aid of the SoCLib tool (this tool has a bunch of hardware models such as processors, memories and interconnections all written in SystemC witch allows you to build embedded systems models).

The platform I'm building consists of a MIPS processor, a RAM, an interconnection and a TTY (virtual terminal), so obviously the MP3 decoder must be cross compiled.

This MP3 decoder uses some C standard libraries that are not instantiated in the SoCLib tool (witch contains only stdio.h and stdlib.h).

I first tried to run my platform without making any changes in the makefiles provided by the SoCLib tool. With this, when I entered the "make" command I got the following messages (among others of the same type):

undefined reference to `tan'

undefined reference to `sin'

undefined reference to `cos'

undefined reference to `memset'

undefined reference to `realloc'

undefined reference to `open'

undefined reference to `strlen'

Researching about this errors, I found that this could be because the linker was not linking the C headers, so I added the following commands (emphasized) on the makefile:

CFLAGS=-Wall -O2 -I. $(ADD_CFLAGS) $(DEBUG_CFLAGS) $($(ARCH)_CFLAGS) -ggdb -I$(COMMON) **-I/usr/include** $(INTERFACE_CFLAGS) 

mipsel-unknown-elf-ld -q $($(ARCH)_LDFLAGS) $(ADD_LDFLAGS) -o $@ $(filter %.o,$^) **-lm** -T $(filter %ldscript,$^) $(LIBGCC)*

However, entering the "make" command again, I got the following error:

mipsel-unknown-elf-ld: cannot find -lm

And now I don't know what to do.

Can anyone help me?


Solution

  • When you entered the "make" command, you got the following error:

    mipsel-unknown-elf-ld: cannot find -lm

    The "mipsel-unknown-elf-" says that you are using the mips cross compiler, and prefixes the "ld" linker-loader command. The -lm option says to link (the "-l" part) the "m" library, which is spelled "libm.a" or "libm.so". Which means that make compiled your code, and now is trying to link your object file with the "libm" library.

    See this link for some more information,

    How does a C compiler find that -lm is pointing to the file libm.a?

    What you want to do now is tell your linker-loader what path(s) to search for your libraries, which means you need to find "libm.a" and/or "libm.so", and the other libraries that you plan to use, "lib*.a" and "lib*.so*". Determine what paths you need, and then you add these library search paths by using the "-L path" option.

    And now you know what to do. -Chuck