0

My application is run in solaris sparc and build with g++ 4.8.2,version detail is:

solaris : SunOS t1000 5.10 Generic_141444-09 sun4v sparc SUNW,Sun-Fire-T1000

g++ : gcc version 4.8.2 (GCC)

First time, I use boost::thread and build application with follow:

g++ -pthreads -lsocket -lnsl -o dist/Debug/GNU-Solaris-Sparc/accagent build/Debug/GNU-Solaris-Sparc/PassengerFlowThread.o build/Debug/GNU-Solaris-Sparc/AccDataTaker.o build/Debug/GNU-Solaris-Sparc/AccCache.o build/Debug/GNU-Solaris-Sparc/Acc.o build/Debug/GNU-Solaris-Sparc/DeviceStatusThread.o build/Debug/GNU-Solaris-Sparc/EntityAccessFactory.o build/Debug/GNU-Solaris-Sparc/BasicSmith.o build/Debug/GNU-Solaris-Sparc/CBThread.o build/Debug/GNU-Solaris-Sparc/SegmentedDeviceStatus.o build/Debug/GNU-Solaris-Sparc/AccInfo.pb.o build/Debug/GNU-Solaris-Sparc/CBException.o build/Debug/GNU-Solaris-Sparc/TimerThread.o build/Debug/GNU-Solaris-Sparc/STEModbusRequest.o build/Debug/GNU-Solaris-Sparc/SegmentedPassengerFlow.o build/Debug/GNU-Solaris-Sparc/ModbusConfigMap.o build/Debug/GNU-Solaris-Sparc/DeviceStatusSmith.o build/Debug/GNU-Solaris-Sparc/StationModeThread.o build/Debug/GNU-Solaris-Sparc/AccMain.o build/Debug/GNU-Solaris-Sparc/ModbusTcpServer.o build/Debug/GNU-Solaris-Sparc/PassengerFlowSmith.o build/Debug/GNU-Solaris-Sparc/CacheKeeper.o build/Debug/GNU-Solaris-Sparc/SegmentedStationMode.o build/Debug/GNU-Solaris-Sparc/AccInfoImpl.o build/Debug/GNU-Solaris-Sparc/AsioClient.o build/Debug/GNU-Solaris-Sparc/AccDataSenderThread.o build/Debug/GNU-Solaris-Sparc/ModbusRequest.o build/Debug/GNU-Solaris-Sparc/AccDataSender.o build/Debug/GNU-Solaris-Sparc/StationModeSmith.o build/Debug/GNU-Solaris-Sparc/AccDataSenderTcpServer.o build/Debug/GNU-Solaris-Sparc/ModbusException.o build/Debug/GNU-Solaris-Sparc/CacheImpl.o build/Debug/GNU-Solaris-Sparc/EventManagerThread.o build/Debug/GNU-Solaris-Sparc/CacheKeeperThread.o build/Debug/GNU-Solaris-Sparc/log.o build/Debug/GNU-Solaris-Sparc/AccAgent.o -L../../../cots/poco_1_4_6/lib/SunOS/sun4v -L../../../cots/protobuf_2_4_1/src/.libs -L../../../cots/boost_1_55_0/stage/lib -L../../../tools/lib -L../../../cots/oracle/1120/solaris10_sparc/lib -L../../../sdk -L../../../cots/RCF_2_0_0_2670/library -lposix4 -lboost_program_options -lboost_system -lboost_filesystem -lboost_thread -lclntsh -lprotobuf -lRCFLibrary -lPocoNetd -lPocoUtild -lPocoFoundationd

when the app was run, the boost::thread cannot create usually.

Second time, I use posix thread and build application with follow:

g++ -pthreads -lsocket -lnsl -o dist/Debug/GNU-Solaris-Sparc/accagent build/Debug/GNU-Solaris-Sparc/PassengerFlowThread.o build/Debug/GNU-Solaris-Sparc/AccDataTaker.o build/Debug/GNU-Solaris-Sparc/AccCache.o build/Debug/GNU-Solaris-Sparc/Acc.o build/Debug/GNU-Solaris-Sparc/DeviceStatusThread.o build/Debug/GNU-Solaris-Sparc/EntityAccessFactory.o build/Debug/GNU-Solaris-Sparc/BasicSmith.o build/Debug/GNU-Solaris-Sparc/CBThread.o build/Debug/GNU-Solaris-Sparc/SegmentedDeviceStatus.o build/Debug/GNU-Solaris-Sparc/AccInfo.pb.o build/Debug/GNU-Solaris-Sparc/CBException.o build/Debug/GNU-Solaris-Sparc/TimerThread.o build/Debug/GNU-Solaris-Sparc/STEModbusRequest.o build/Debug/GNU-Solaris-Sparc/SegmentedPassengerFlow.o build/Debug/GNU-Solaris-Sparc/ModbusConfigMap.o build/Debug/GNU-Solaris-Sparc/DeviceStatusSmith.o build/Debug/GNU-Solaris-Sparc/StationModeThread.o build/Debug/GNU-Solaris-Sparc/AccMain.o build/Debug/GNU-Solaris-Sparc/ModbusTcpServer.o build/Debug/GNU-Solaris-Sparc/PassengerFlowSmith.o build/Debug/GNU-Solaris-Sparc/CacheKeeper.o build/Debug/GNU-Solaris-Sparc/SegmentedStationMode.o build/Debug/GNU-Solaris-Sparc/AccInfoImpl.o build/Debug/GNU-Solaris-Sparc/AsioClient.o build/Debug/GNU-Solaris-Sparc/AccDataSenderThread.o build/Debug/GNU-Solaris-Sparc/ModbusRequest.o build/Debug/GNU-Solaris-Sparc/AccDataSender.o build/Debug/GNU-Solaris-Sparc/StationModeSmith.o build/Debug/GNU-Solaris-Sparc/AccDataSenderTcpServer.o build/Debug/GNU-Solaris-Sparc/ModbusException.o build/Debug/GNU-Solaris-Sparc/CacheImpl.o build/Debug/GNU-Solaris-Sparc/EventManagerThread.o build/Debug/GNU-Solaris-Sparc/CacheKeeperThread.o build/Debug/GNU-Solaris-Sparc/log.o build/Debug/GNU-Solaris-Sparc/AccAgent.o -L../../../cots/poco_1_4_6/lib/SunOS/sun4v -L../../../cots/protobuf_2_4_1/src/.libs -L../../../cots/boost_1_55_0/stage/lib -L../../../tools/lib -L../../../cots/oracle/1120/solaris10_sparc/lib -L../../../sdk -L../../../cots/RCF_2_0_0_2670/library -lposix4 -lboost_program_options -lboost_system -lboost_filesystem -lboost_thread -lclntsh -lprotobuf -lRCFLibrary -lPocoNetd -lPocoUtild -lPocoFoundationd

the app some times dump with follow info:

Program terminated with signal 11, Segmentation fault.

[New process 735251 ]

[New process 800787 ]

[New process 866323 ]

[New process 931859 ]

[New process 997395 ]

[New process 79891 ]

[New process 407571 ]

[New process 538643 ]

[New process 604179 ]

[New process 669715 ]

0 0xfdbbe7fc in elf_find_sym () from /usr/lib/ld.so.1

Third time, I also use posix thread and build with follow (add -lpthread):

g++ -lpthread -pthreads -lsocket -lnsl -o dist/Debug/GNU-Solaris-Sparc/accagent build/Debug/GNU-Solaris-Sparc/PassengerFlowThread.o build/Debug/GNU-Solaris-Sparc/AccDataTaker.o build/Debug/GNU-Solaris-Sparc/AccCache.o build/Debug/GNU-Solaris-Sparc/Acc.o build/Debug/GNU-Solaris-Sparc/DeviceStatusThread.o build/Debug/GNU-Solaris-Sparc/EntityAccessFactory.o build/Debug/GNU-Solaris-Sparc/BasicSmith.o build/Debug/GNU-Solaris-Sparc/CBThread.o build/Debug/GNU-Solaris-Sparc/SegmentedDeviceStatus.o build/Debug/GNU-Solaris-Sparc/AccInfo.pb.o build/Debug/GNU-Solaris-Sparc/CBException.o build/Debug/GNU-Solaris-Sparc/TimerThread.o build/Debug/GNU-Solaris-Sparc/STEModbusRequest.o build/Debug/GNU-Solaris-Sparc/SegmentedPassengerFlow.o build/Debug/GNU-Solaris-Sparc/ModbusConfigMap.o build/Debug/GNU-Solaris-Sparc/DeviceStatusSmith.o build/Debug/GNU-Solaris-Sparc/StationModeThread.o build/Debug/GNU-Solaris-Sparc/AccMain.o build/Debug/GNU-Solaris-Sparc/ModbusTcpServer.o build/Debug/GNU-Solaris-Sparc/PassengerFlowSmith.o build/Debug/GNU-Solaris-Sparc/CacheKeeper.o build/Debug/GNU-Solaris-Sparc/SegmentedStationMode.o build/Debug/GNU-Solaris-Sparc/AccInfoImpl.o build/Debug/GNU-Solaris-Sparc/AsioClient.o build/Debug/GNU-Solaris-Sparc/AccDataSenderThread.o build/Debug/GNU-Solaris-Sparc/ModbusRequest.o build/Debug/GNU-Solaris-Sparc/AccDataSender.o build/Debug/GNU-Solaris-Sparc/StationModeSmith.o build/Debug/GNU-Solaris-Sparc/AccDataSenderTcpServer.o build/Debug/GNU-Solaris-Sparc/ModbusException.o build/Debug/GNU-Solaris-Sparc/CacheImpl.o build/Debug/GNU-Solaris-Sparc/EventManagerThread.o build/Debug/GNU-Solaris-Sparc/CacheKeeperThread.o build/Debug/GNU-Solaris-Sparc/log.o build/Debug/GNU-Solaris-Sparc/AccAgent.o -L../../../cots/poco_1_4_6/lib/SunOS/sun4v -L../../../cots/protobuf_2_4_1/src/.libs -L../../../cots/boost_1_55_0/stage/lib -L../../../tools/lib -L../../../cots/oracle/1120/solaris10_sparc/lib -L../../../sdk -L../../../cots/RCF_2_0_0_2670/library -lposix4 -lboost_program_options -lboost_system -lboost_filesystem -lboost_thread -lclntsh -lprotobuf -lRCFLibrary -lPocoNetd -lPocoUtild -lPocoFoundationd

now the app is running about one day with no crash and any other exceptions.

My question is :

1)What is the difference between -lpthread and -pthreads?

2)Is "/usr/lib/ld.so.1" influences my app?

3)Am I resolve the problem with both link with -lpthread and -pthreads?

By the way, without -pthreads, my app can't pass the build.

Community
  • 1
  • 1
Zebiak
  • 1
  • 1
  • 2
  • I check my gcc dumpspecs as follow: -bash-3.00$ gcc -dumpspecs | grep pthread %{compat-bsd:-lucb -lsocket -lnsl -lelf -laio} %{!shared: %{!symbolic: %{pthreads:-lpthread} %{!pthreads:%{threads:-lthread}} %{p|pg:-ldl} -lc}} %{pthreads:-D_REENTRANT -D_PTHREADS} %{!pthreads:%{threads:-D_REENTRANT -D_SOLARIS_THREADS}} %{compat-bsd:-iwithprefixbefore ucbinclude -I/usr/ucbinclude} – Zebiak Apr 11 '14 at 02:35
  • possible duplicate of [gcc - significance of -pthread flag when compiling](http://stackoverflow.com/questions/2127797/gcc-significance-of-pthread-flag-when-compiling) – juanchopanza Apr 11 '14 at 05:45

2 Answers2

1

In general, when you use the -l option during linking, it tells to link the program with the named library, thus -lpthread indicates to link with the pthread library, having filename of library as libpthread.a, libpthread.so or similar.

The include file contains declarations for the Oracle Solaris threads functions. The include file contains declarations for the Pthreads functions.

Linker flag -lpthread indicates to link in the pthread APIs (libpthread library), and the -mt option links in the libthread library. Both flags are needed when using Pthreads because libpthread provides an interface to libthread.

Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
0

At last I find the dump is case my protocol buffer link problem.In my protocol buffer's .libs dir wasn't find libprotoc.so.7.0's softlink (libprotoc.so),so it was auto link the libprotoc.a . I create the dynamic link as libprotoc.so point to libprotoc.so.7.0 . The problem is resovled.

Zebiak
  • 1
  • 1
  • 2