比如说我们有文件main.c,threadpool.c,threadpool.h
main.c和threadpool.c都用了threadpool.h,也就是#include "threadpool.h"
(1)如果我们直接使用gcc main.c -o a.out -lpthread会报如下的错
我们需要进行动态库链接
gcc -c threadpool.c -o threadpool.o
ar -rcs libadd.a threadpool.o
gcc main.c -o a.out libadd.a -lpthread
(2)运行./a.out的时候如果出现段错误等其他错误,我们想要查看错误信息,可以在gdb中利用core文件来查看错误信息。
sudo service apport stop
ulimit -c unlimited
gcc -c threadpool.c -o threadpool.o
ar -rcs libadd.a threadpool.o
gcc main.c -o a.out libadd.a -lpthread
./a.out
生成core文件后,gdb a.out
gdb调试:core-file core