I compile the latest buildroot, and use the output host mipsel-linux-gcc
to compile my c program. I have tested the hello world program and it run fine on MIPS machine(actually a router flashed with padavan). Then I compiled my program and it run good util it calls pthread_create
, showing that it can't resolve symbol pthread_create
.
I thought maybe it's because the router doesn't have libpthread.so, so I checked:
[RT-AC54U /home/root]# find / -name "*pthread*"
/lib/libpthread-0.9.33.2.so
/lib/libpthread.so.0
it turned out the libpthread so file does exist.
Then I suspected maybe it's cause by the cross compilation setting. So I checked the link library by adding -L. -Wl,--verbose
options (learned from other SO post) and find:
attempt to open buildroot/output/host/usr/mipsel-buildroot-linux-uclibc/sysroot/usr/
lib/libpthread.a succeeded
when linking, linker only finds the libpthread.a
, all libpthread.so
searching fail. Seeing this I checked using find . -name "*pthread.so"
in the buildroot directory and find nothing.
If linker only find the pthread static library then why it doesn't complaint? I skimmed through the make menuconfig
and have not seen any option concerning pthread library.
The readelf output is:
readelf -d ./myprogram |grep NEEDED
0x00000001 (NEEDED) Shared library: [libc.so.0]
We could see that the program doesn't include the need for libpthread
! Compared with the same program compiled by native(x64) gcc:
readelf -d ./myprogram |grep NEEDED
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
My best guess now is that mipsel-linux-gcc
can't find libpthread.so
,thus didn't add information about libpthread to executable. Though strangely it didn't complain at all.
Could anyone tell me what's wrong? Thank you.