(笔记)Linux线程编译undefined reference to 'pthread_create'

在使用线程时,使用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.c -lpthread

请注意后面的-lpthread,特别是-后边的‘l‘,link = ‘l‘

(笔记)Linux线程编译undefined reference to 'pthread_create'

时间: 2024-08-28 09:31:06

(笔记)Linux线程编译undefined reference to 'pthread_create'的相关文章

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 &#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

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

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

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

linux下出现undefined reference to mysql init&#39; 的解决方法

查看mysql配置的命令叫:mysql_config -L/usr/lib64/mysql -lmysqlclient \ 1.命令行后加入 -lmysqlclient 附有一个查看mysql配置的命令叫:mysql_config 再分享一下我老师大神的人工智能教程吧.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net linux下出现undefined reference to mysql init' 的解决方法 原

Ubuntu使用多线程cmake时出现undefined reference to `pthread_create&#39;

原因是ubuntu需要查找Threads第三方库,不能直接使用,因此,在cmakelists.txt文件中添加以下两行代码就ok find_package(Threads) target_link_libraries(HELLO ${CMAKE_THREAD_LIBS_INIT})   Ubuntu使用多线程cmake时出现undefined reference to `pthread_create' 原文地址:https://www.cnblogs.com/excellentlhw/p/108

PHP无法编译undefined reference to `libiconv_open

./configure --prefix=/usr/local/php52 make时提示:.....................................................ext/iconv/.libs/iconv.o(.text+0x1738): In function `zif_iconv_mime_encode':/usr/src/php-5.2.0/ext/iconv/iconv.c:1017: undefined reference to `libiconv_

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

问题的原因:pthread不是Linux下的默认的库,也就是在链接的时候,无法找到phread库中函数的入口地址,于是链接会失败. 解决:在gcc编译的时候,附加要加 -lpthread参数即可解决. 原文地址:https://www.cnblogs.com/zhizhiyu/p/10295013.html