在openwrt下添加xcom包编译出现如下错误:
xcom.c:(.text.startup+0x24): undefined reference to `pthread_create'
原因分析: pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。
解决方法:
第一步:makefile中连接阶段添加 -lphtread
xcom: xcom.o
$(CC) $(LDFLAGS) xcom.o -o xcom -lpthread
第二步:上一级makefile 添加依赖DEPENDS:=+libpthread +librt。
define Package/xcom
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Xcom -- prints a snarky message
DEPENDS:=+libpthread +librt
即可。