Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 能够在没有pthread的情况下链接并且程序仍然运行吗?_C++_Linux_G++_Pthreads - Fatal编程技术网

C++ 能够在没有pthread的情况下链接并且程序仍然运行吗?

C++ 能够在没有pthread的情况下链接并且程序仍然运行吗?,c++,linux,g++,pthreads,C++,Linux,G++,Pthreads,我正在查看一个同事的消息队列库,发现它不起作用,但对他来说起作用了。经过几天的苦思冥想,我终于意识到我没有在命令行上使用“-lpthread”。当我这么做的时候,突然间世界又恢复了正常。这是怎么发生的?在我的例子中,我知道pthread是一个动态链接的库。如果我编译我的示例代码(我想这与-lpthread无关),就好像链接器或操作系统只是在填补空白,如果你愿意的话,存根例程什么都不做。如果我提供了-lpthread标志并在gdb中运行程序,则会出现以下行: Using host libthrea

我正在查看一个同事的消息队列库,发现它不起作用,但对他来说起作用了。经过几天的苦思冥想,我终于意识到我没有在命令行上使用“-lpthread”。当我这么做的时候,突然间世界又恢复了正常。这是怎么发生的?在我的例子中,我知道pthread是一个动态链接的库。如果我编译我的示例代码(我想这与-lpthread无关),就好像链接器或操作系统只是在填补空白,如果你愿意的话,存根例程什么都不做。如果我提供了-lpthread标志并在gdb中运行程序,则会出现以下行:

Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
在没有标记的情况下重新编译程序并使用gdb时,没有提到包含phtreads,这是有意义的。我用的是覆盆子皮,如果有关系的话

g++--版本报告:

g++ (Debian 4.6.3-14+rpi1) 4.6.3
很明显,如果可以的话,这是我想要解决的问题


使用“nm”在两个可执行文件上转储符号表,至少对于pthread符号而言,没有任何差异。

使用我的原始Raspberry Pi基准测试,可以使用以下方法编译线程程序:

 gcc  mpmflops.c cpuidc.c -lrt -lc -lm -O3 -o MP-MFLOPS2
 with gcc (Debian 4.6.3-14+rpi1) 4.6.3
这不会在RPI2上编译,需要

 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
参考:


使用我最初的Raspberry Pi基准测试,可以使用以下方法编译线程程序:

 gcc  mpmflops.c cpuidc.c -lrt -lc -lm -O3 -o MP-MFLOPS2
 with gcc (Debian 4.6.3-14+rpi1) 4.6.3
这不会在RPI2上编译,需要

 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
参考:


如果不链接到pthread,您应该有一个
std::system\u错误
(这解释了您的问题)“应该”,但我没有得到任何异常,没有核心文件,什么都没有。您不应该使用
-lpthread
。您应该使用平台文档中所说的任何东西来获得POSIX pthreads支持。我很确定在您的平台上是
-pthread
。如果不链接到pthread,您应该有一个
std::system_错误
(这解释了您的问题)“应该”,但我没有得到任何异常,没有核心文件,什么都没有。您不应该使用
-lpthread
。您应该使用平台文档中所说的任何东西来获得POSIX pthreads支持。我很确定在您的平台上是
-pthread