Menu

#61 Use -pthread not -lpthread in swrx Jamfile

Untested
closed-invalid
nobody
Application (6)
5
2014-01-27
2013-01-14
Doug Morgan
No

To make apps/swrx/trackerMT and RX link with any setup of of gcc, you need to use -pthread, not -lpthread in apps/swrx/Jamfile. As it is, in my ubuntu 12.04, trackerMTand RX don't link:
% jam -dx
build/install of mdpscreenx is being skipped; see jamfile

cc -lpthread -o apps/swrx/trackerMT apps/swrx/trackerMT.o apps/swrx/simlib.a src/libgpstk.a -lm -lstdc++

apps/swrx/trackerMT.o: In function `RxSim::process()':
trackerMT.cpp:(.text+0x3b4f): undefined reference to `pthread_create'
trackerMT.cpp:(.text+0x3bba): undefined reference to `pthread_join'
collect2: ld returned 1 exit status

cc -lpthread -o apps/swrx/RX apps/swrx/RX.o apps/swrx/simlib.a src/libgpstk.a -lm -lstdc++

apps/swrx/RX.o: In function `RxSim::process()':
RX.cpp:(.text+0x42aa): undefined reference to `pthread_create'
RX.cpp:(.text+0x4312): undefined reference to `pthread_join'
collect2: ld returned 1 exit status

However, they link fine with -pthread instead of -lpthread. See this page for pretty clear explanation of why -pthread is always the right thing to do:
http://stackoverflow.com/questions/2127797/gcc-significance-of-pthread-flag-when-compiling

This bug is in gpstk-2.0.src.tar.gz (and rev 1555 of the Jamfile).

Discussion

  • Doug Morgan

    Doug Morgan - 2013-01-15

    Oops. I'll just let you figure out how to fix this. Two fixes are: 1) using -pthread instead of -lpthread and 2) adding -lpthread to LINKLIBS instead of LINKFLAGS. Incorrectly putting -lpthread in LINKFLAGS results in -lpthread being included on the final command line too early (before the *.o files that use the library). Both these solutions seem pretty gcc-centric. I think an OS/compiler independent solution may be more involved. Good luck.

     
  • Doug Morgan

    Doug Morgan - 2013-01-15

    Oops again. I forgot to add that if you think adding -pthread to LINKFLAGS (instead of -lpthread) is good (I think it is much better than messing with -lpthread), then to be consistent and to work with different ways that gcc can be configured, -pthread should also be added to C++FLAGS.

     
  • Bryan Parsons

    Bryan Parsons - 2014-01-27
    • status: open --> closed-invalid
    • Group: --> Untested