1

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.

Allan Ruin
  • 5,229
  • 7
  • 37
  • 42

1 Answers1

0

Try adding -lpthread in compilation command

e.g.:

gcc <source file>.c -o <object file name> -lpthread

gcc is the compiler command.

-lpthread is option to execute pthread.h library file.

BhanuSingh
  • 118
  • 1
  • 2
  • 15
  • ==,well, I forget to mention I did use `-pthread` in gcc command. Thank you for your advise – Allan Ruin Mar 04 '17 at 04:13
  • Maybe you could have a look at this SO post:http://stackoverflow.com/questions/23250863/difference-between-pthread-and-lpthread-while-compiling Using the -lpthread option only causes the pthread library to be linked - the pre-defined macros don't get defined. – Allan Ruin Mar 04 '17 at 04:17
  • By the way, I confirm that switch to `-lpthread` doesn't make a difference, still see no pthread NEEDED part in elf file I will working on find a MIPS libpthread.so to place in buildroot and see what happened – Allan Ruin Mar 04 '17 at 04:20