Trouble building a MIPS compatible C static librar

2019-09-06 17:17发布

问题:

I'm trying to build a C static library (.a) that is compatible with a MIPS processor (I'm working in an embedded system).

To do so I tried to execute the following commands (obs: I'm using the mipsel-unknown-elf tool):

mipsel-unknown-elf-gcc -o math.o -c math.c

(No erros followed this command)

 mipsel-unknown-elf-gcc -archive -o libmath.a math.o -lm

With this command I got the following error message:

cannot find -lm

collect2: ld returned 1 exit status

By getting this message I tried to add a -L/path argument:

mipsel-unknown-elf-gcc -archive -o libmath.a math.o -L/usr/lib/i386-linux-gnu -lm

But then I got the following error:

skipping incompatible /usr/lib/i386-linux-gnu/libm.a when searching for -lm

cannot find -lm

collect2: ld returned 1 exit status

Does anyone knows what's going on?

回答1:

Your cross compiler distribution should include a MIPS libm.a. I just checked and I found several libm.a versions in my installation of CodeSourcery mips-linux-gnu-gcc. I don't have mipsel-unknown-elf-gcc installed, so I can't check that. If the mips-linux-gnu- version of libm.a is self contained, you might try using that version.