我有 3 个文件my_pipe.h
、、、my_pipe.c
和main.c
,my_pipe
应该是一个库。
当我在 Eclipse 中编译它时,它编译得很好,没有错误,但是当我运行以下makefile
命令并terminal
点击时make
:
exer3: main.o libmywrapper.a
gcc main.c libmywrapper.a -o exer3 -static -lrt
libmywrapper.a: my_pipe.o
ar rcs libmywrapper.a my_pipe.o
main.o: main.c my_pipe.h
gcc -lpthread -lrt -c main.c
my_pipe.o: my_pipe.c my_pipe.h
gcc -lpthread -lrt -c my_pipe.c
我明白了:
a@ubuntu:~/Desktop/myExer$ make
gcc -lpthread -lrt -c main.c
gcc -lpthread -lrt -c my_pipe.c
ar rcs libmywrapper.a my_pipe.o
gcc main.c libmywrapper.a -o exer3 -static -lrt
libmywrapper.a(my_pipe.o): In function `shm_pipe_init':
my_pipe.c:(.text+0x61): undefined reference to `sem_init'
libmywrapper.a(my_pipe.o): In function `shm_pipe_read':
my_pipe.c:(.text+0x17f): undefined reference to `sem_wait'
my_pipe.c:(.text+0x196): undefined reference to `sem_getvalue'
my_pipe.c:(.text+0x1ba): undefined reference to `sem_wait'
libmywrapper.a(my_pipe.o): In function `shm_pipe_write':
my_pipe.c:(.text+0x4b7): undefined reference to `sem_post'
collect2: ld returned 1 exit status
make: *** [exer3] Error 1
知道makefile有什么问题吗?
谢谢
更新,上面!