[Linux] Linux下undefined reference to ‘pthread_create’问题解决

问题的原因:pthread不是Linux下的默认的库,也就是在链接的时候,无法找到phread库中函数的入口地址,于是链接会失败。

解决:在gcc编译的时候,附加要加 -lpthread参数即可解决。

原文地址:https://www.cnblogs.com/zhizhiyu/p/10295013.html

时间: 2024-07-28 15:59:12

[Linux] Linux下undefined reference to ‘pthread_create’问题解决的相关文章

Debian下undefined reference to ‘pthread_create’问题解决

今天在写线程测试程序(pthread_create)时出现如下问题, 明明在头文件中包含了<pthread.h>,但是仍然提示找不到函数 pthread_create 和 pthread_join,查资料得知, pthread不是linux下的默认库,也就是在链接的时候,无法找到pthread库文件各个函数入口地址,于是链接会失败. 解决方法,在进行gcc编译的时候,附加上 -lpthread 参数. 原文地址:https://www.cnblogs.com/rohens-hbg/p/8616

(笔记)Linux线程编译undefined reference to &#39;pthread_create&#39;

在使用线程时,使用gcc或arm-linux-gcc编译时,会出现错误:undefined reference to 'pthread_create' 主要是以下两种原因: 1.#include <pthread.h>  请确认头文件是否添加 2.-lpthread 编译选项,即在编译时需添加额外的编译选项,如使用arm-linux-gcc编译lc300-led-test.c文件,命令正确应该如下: arm-linux-gcc -o lc300-led-test lc300-led-test.

undefined reference to `pthread_create&#39;问题解决

在编译pthread有关的程序时,出现undefined reference to `pthread_create'这样的错误. 问题原因: pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库. 问题解决: 方法一: 在编译中要加 -lpthread参数gcc thread.c -o thread -lpthread

linux 线程操作问题undefined reference to &#39;pthread_create&#39;的解决办法(cmake)

问题原因: pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a. 所以在使用pthread_create()创建线程时,需要链接该库. 1. 终端:问题解决:在编译中要加 -pthread参数 gcc thread.c -o thread -pthread 2. qt的cmake配置: 可以修改CMakeLists.txt: Here is the right answer: ADD_EXECUTABLE(your_executable ${sour

undefined reference to `sin&#39;问题解决

作者:zhanhailiang 日期:2014-10-25 使用gcc编译如下代码时报"undefined reference to `sin'": #include <stdio.h> #include <math.h> #include <stdlib.h>   main () { double a = sin(1); exit (0); } [root@~/wade/codeReview/learningc/9]# gcc -o timetes

undefined reference to `pthread_create&#39; collect2: ld returned 1 exit status

Linux下编译多线程程序遇到错误: undefined reference to `pthread_create' collect2: ld returned 1 exit status 原因是系统无法找到pthread_create函数.也就是说编译器在link得时候找不到其中的一个使用库的函数. 解决办法如下: For Linux the correct command is: gcc -pthread xxx.c In general, libraries should follow s

线程异常:undefined reference to &#39;pthread_create&#39; 处理

源码: #include <stdio.h> #include <pthread.h> #include <sched.h> void *producter_f (void *arg); void *consumer_f (void *arg); int buffer_has_item=0; pthread_mutex_t mutex; int running =1 ; int main (void) { pthread_t consumer_t; pthread_t

pthread.h 的 undefined reference to `pthread_create&#39;

在编译中要加 -lpthread或-pthread参数(不同版本的gcc可能不一样,man gcc可以查阅对应参数). 例如:在加了头文件#include <pthread.h>之后执行 pthread.c文件,需要使用如下命令: gcc -lpthread -o thread thread.c 或 gcc -pthread -o thread thread.c 这种情况类似于<math.h>的使用,需在编译时加 -m 参数. pthread.h 的 undefined refer

undefined reference to `_init&#39;问题解决

今天利用CDT 的eclipse调试程序,遇到下面的问题: d:/plugin/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7-m\libg_s.a(lib_a-init.o): In function `__libc_init_array':init.c:(.text.__libc_init_array+0x1c): undefined reference to `_init'collect2.exe