在Linux中使用线程相关的东西就要使用到这个头文件,但这还不算。如果仅仅使用这个头文件,会出现错误:

 

undefined reference to `pthread_create'
collect2: ld returned 1 exit status
make: *** [threadid] Error 1

 

     之所以出现这样的错误,是因为我们没有链接相应的函数库。所以在编译的时候要加上 –lpthread 选项。

     Makefile文件如下:

CC = gcc
CFLAGS = -I/home/cat/apue/apue.2e/include -Wall -g

threadid: threadid.o
    $(CC) $(CFLAGS) -o $@ $^ -lpthread
GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:23 天前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐