2

I was checking out a coworkers message queue library and found that it didn't work, but it did for him. After days of scratching our heads I eventually realized that I wasn't doing "-lpthread" on the command line. When I did, suddenly everything was right with the world again. How does this happen? I get it that pthread, in my case, is a dynamically-linked library. If I compile my sample code (which isn't relavant here, I think) without the -lpthread, it's like the linker or OS is just filling in the blanks, if you will, with stub routines that do nothing. If I do supply the -lpthread flag and run the program in gdb, this line appears:

Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".

Recompiling the program without the flag and using gdb mentions no inclusion of phtreads, which makes sense. I'm using a Raspberry Pi here, if that matters.

g++ --version reports:

g++ (Debian 4.6.3-14+rpi1) 4.6.3

Obviously this is something I'd like to fix, if you can.

Using "nm" to dump the symbol table on the two executables reveals no differences, at least for pthread symbols.

Kelly Beard
  • 684
  • 1
  • 8
  • 20
  • Not linking to pthread, you should have an `std::system_error` (which explains you problem) –  Jun 22 '15 at 18:43
  • "Should", but I don't get any exception at all, no core file, nothing. – Kelly Beard Jun 22 '15 at 18:45
  • You shouldn't be using `-lpthread`. You should be using whatever your platform documentation says you should use to get POSIX pthreads support. I'm pretty sure that's `-pthread` on your platform. [Here's one reason why.](http://stackoverflow.com/a/23251828/721269) – David Schwartz Jun 22 '15 at 23:47

1 Answers1

-1

With my original Raspberry Pi benchmarks a threaded program could be compiled using such as:

 gcc  mpmflops.c cpuidc.c -lrt -lc -lm -O3 -o MP-MFLOPS2
 with gcc (Debian 4.6.3-14+rpi1) 4.6.3

This would not compile on RPi 2 and needed

 gcc  mpmflops.c cpuidc.c -lpthread -lrt -lc -lm -O3 -o MP-MFLOPS2
 again with gcc (Debian 4.6.3-14+rpi1) 4.6.3 and 
 or gcc (Raspbian 4.8.2-21~rpi3rpi1) 4.8.2

Reference:

http://www.roylongbottom.org.uk/Raspberry%20Pi%20Multithreading%20Benchmarks.htm

Roy Longbottom
  • 1,192
  • 1
  • 6
  • 8