0528.c:(.text+0x4c):对‘pthread_create’未定义的引用 0528.c:(.text+0x67):对‘pthread_create’未定义的引用 0528.c:(.text+0x78):对‘pthread_join’未定义的引用 0528.c:(.text+0x89):对‘pthread_join’未定义的引用 collect2: 错误:ld 返回 1
时间: 2023-08-11 18:17:56 浏览: 59
这个错误提示意味着编译器找不到 `pthread_create()` 和 `pthread_join()` 函数的定义。这通常是因为在编译时没有链接线程库造成的。
在 Linux 系统中,需要链接 `-pthread` 选项来使用线程库。所以,你需要在编译时加上 `-pthread` 选项,例如:
```
gcc -pthread 0528.c -o 0528
```
这样就可以编译并链接线程库,解决这个错误。
相关问题
fuwuduan.c:(.text+0x19e):对‘pthread_create’未定义的引用
这个错误是因为在编译时没有链接 pthread 库,你需要在编译命令中加上 `-pthread` 选项来链接 pthread 库。例如:
```
gcc -pthread fuwuduan.c -o fuwuduan
```
如果你是使用 Makefile 进行编译,可以在 Makefile 中的 CFLAGS 变量中添加 `-pthread` 选项,例如:
```
CFLAGS=-Wall -pthread
```
然后在编译命令中使用 $(CFLAGS) 变量,例如:
```
gcc $(CFLAGS) fuwuduan.c -o fuwuduan
```
thread.cpp:(.text+0x82): undefined reference to `pthread_create'
这个错误出现在编译时,是因为在链接过程中找不到对应的pthread_create函数的定义。该函数属于pthread库,但在链接时没有使用正确的静态库libpthread.a。因此,需要在编译命令中明确指定使用pthread库,以解决该问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [undefined reference to ‘pthread_create’的解决方法](https://download.csdn.net/download/weixin_38698860/14890861)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [Juliet Test make报错:std_thread.c:(.text+0xae): undefined reference to `pthread_create](https://blog.csdn.net/u013648063/article/details/115633638)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [Linux:In function `main‘:xc.c:(.text+0x11c): undefined reference to `pthread_create‘xc....](https://blog.csdn.net/weixin_62979816/article/details/130534073)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]