简体   繁体   English

SoCLib工具中使用C标准库的困难

[英]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). 我正在尝试将一个名为minimp3的MP3解码器(用C语言编写)移植到借助SoCLib工具构建的平台上(该工具具有一堆硬件模型,例如处理器,内存和互连,全部用SystemC编写)。允许您构建嵌入式系统模型)。

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. 我正在构建的平台由MIPS处理器,RAM,互连和TTY(虚拟终端)组成,因此,显然必须对MP3解码器进行交叉编译。

This MP3 decoder uses some C standard libraries that are not instantiated in the SoCLib tool (witch contains only stdio.h and stdlib.h). 此MP3解码器使用一些未在SoCLib工具中实例化的C标准库(witch仅包含stdio.h和stdlib.h)。

I first tried to run my platform without making any changes in the makefiles provided by the SoCLib tool. 我首先尝试在不对SoCLib工具提供的makefile进行任何更改的情况下运行平台。 With this, when I entered the "make" command I got the following messages (among others of the same type): 这样,当我输入“ make”命令时,得到以下消息(以及其他相同类型的消息):

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: 研究此错误后,我发现这可能是因为链接器未链接C头,所以我在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: 但是,再次输入“ make”命令,出现以下错误:

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

And now I don't know what to do. 现在我不知道该怎么办。

Can anyone help me? 谁能帮我?

When you entered the "make" command, you got the following error: 输入“ make”命令时,出现以下错误:

mipsel-unknown-elf-ld: cannot find -lm mipsel-unknown-elf-ld:找不到-lm

The "mipsel-unknown-elf-" says that you are using the mips cross compiler, and prefixes the "ld" linker-loader command. “ mipsel-unknown-elf-”表示您正在使用mips交叉编译器,并在“ ld”链接程序加载程序命令前加上前缀。 The -lm option says to link (the "-l" part) the "m" library, which is spelled "libm.a" or "libm.so". -lm选项表示链接(“ -l”部分)“ m”库,该库的拼写为“ libm.a”或“ libm.so”。 Which means that make compiled your code, and now is trying to link your object file with the "libm" library. 这意味着make编译了您的代码,现在正在尝试将目标文件与“ libm”库链接。

See this link for some more information, 有关更多信息,请参见此链接,

How does a C compiler find that -lm is pointing to the file libm.a? C编译器如何发现-lm指向文件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*". 您现在想要做的就是告诉链接加载程序要搜索库的路径,这意味着您需要找到“ libm.a”和/或“ libm.so”以及计划的其他库。使用“ lib * .a”和“ lib * .so *”。 Determine what paths you need, and then you add these library search paths by using the "-L path" option. 确定所需的路径,然后使用“ -L路径”选项添加这些库搜索路径。

And now you know what to do. 现在您知道该怎么办了。 -Chuck -查克

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM