+ -
当前位置:首页 → 问答吧 → 关于apue的静态库

关于apue的静态库

时间:2011-12-23

来源:互联网

大家好,我在redhat上面编译好了《UNIX环境高级编程(第二版)》的源码,并且把lib/libapue.a拷贝到了/usr/lib。但是
在使用其中一个例子名为“cleanup”程序的时候,链接出错了,具体命令如下:
gcc -o test cleanup.c -lapue

系统提示:
/tmp/ccSjphRZ.o(.text+0x43): In function `thr_fn1':
: undefined reference to `_pthread_cleanup_push'
/tmp/ccSjphRZ.o(.text+0x5c): In function `thr_fn1':
: undefined reference to `_pthread_cleanup_push'
/tmp/ccSjphRZ.o(.text+0x85): In function `thr_fn1':
: undefined reference to `_pthread_cleanup_pop'
/tmp/ccSjphRZ.o(.text+0x96): In function `thr_fn1':
: undefined reference to `_pthread_cleanup_pop'
/tmp/ccSjphRZ.o(.text+0xcc): In function `thr_fn2':
: undefined reference to `_pthread_cleanup_push'
/tmp/ccSjphRZ.o(.text+0xe5): In function `thr_fn2':
: undefined reference to `_pthread_cleanup_push'
/tmp/ccSjphRZ.o(.text+0x116): In function `thr_fn2':
: undefined reference to `_pthread_cleanup_pop'
/tmp/ccSjphRZ.o(.text+0x127): In function `thr_fn2':
: undefined reference to `_pthread_cleanup_pop'
/tmp/ccSjphRZ.o(.text+0x156): In function `main':
: undefined reference to `pthread_create'
/tmp/ccSjphRZ.o(.text+0x193): In function `main':
: undefined reference to `pthread_create'
/tmp/ccSjphRZ.o(.text+0x1cd): In function `main':
: undefined reference to `pthread_join'
/tmp/ccSjphRZ.o(.text+0x21a): In function `main':
: undefined reference to `pthread_join'

请问为什么系统找不到/usr/lib/libapue.a呢?
谢谢!

作者: chennut0802   发布时间: 2011-12-23

另外请问我用这个Makefile:
CXX = gcc
CXXFLAGS = -g -Wall
INCLUDE = -I./
LIB = -lapue -lpthread
LIBS =

SRC_PATH = ./

SRCS := $(wildcard $(SRC_PATH)/*.c)
OBJS := $(patsubst %.c, %.d.o, $(SRCS))

TARGET = ./mainTest

%.d.d : %.c
  @set -e; rm -f $@; \
  $(CXX) -MM $(CXXFLAGS) $(INCLUDE) $< > $@.$$$$; \
  sed 's,.*\.o[ ]*:,$*.o $@ :,g'< $@.$$$$ > $@; \
  rm -f $@.$$$$
  $(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $*.d.o $<

$(TARGET):$(OBJS)
  $(CXX) -o $(TARGET) $(OBJS) $(LIB)

include $(SRCS:.c/=.d.d)

.PHONY:clean
clean:
  rm -f ./src/*.r.o $(TARGET) ./src/*.d.d ./tinyxml/src/*.d.o ./tin

执行make之后,会提示:
main.c:4: *** missing separator. Stop.

作者: chennut0802   发布时间: 2011-12-23

gcc -o test cleanup.c -lapue -lpthread

作者: zmlovelx   发布时间: 2011-12-23

请问学过《UNIX环境高级编程(第二版)》的朋友,libapue.a不包括libpthread的内容吗?

作者: chennut0802   发布时间: 2011-12-23

加上-lpthread

作者: icechenbing   发布时间: 2011-12-23

-lpthread
编译时连接pthread库,实现多线程需要用到这个库里的函数。

作者: liuchao35758600   发布时间: 2011-12-23