历经一个月,昨日完成打印机network部分的编写(c语言),编写makefile构建动态库。构建完成后遂进行调用测试,出现:
./network: symbol lookup error: /usr/lib64/netPrnctl.so: undefined symbol: cupsGetDests
将解决方法与过程记录,以便日后查阅。
查找与分析原因
在编译时未出现问题,没有报错,成功编译生成动态库。以下为编译的makefile文件。
###########################################################
# File: netPrnctl.so Makefile
# Author: Neko
###########################################################
CC = gcc
CFLAGS = -Wall -g -fPIC
INCLUDE = -I./inc -I../ -I../cups -I../backend -I/usr/include/libusb-1.0
TARGET = netPrnctl.so
vpath % .h ./inc
OBJS = public.o prnctlAvision.o prnctlNetwork.o prnctl.o
SRCS = ./src/public.c ./src/prnctlAvision.c ./src/prnctlNetwork.c ./src/prnctl.c
$(OBJS):$(SRCS)
$(CC) $(CFLAGS) $(INCLUDE) -c $^
all:$(OBJS)
$(CC) -shared -fPIC -o $(TARGET) $(OBJS) -pthread
cp $(TARGET) /usr/bin
cp $(TARGET) /usr/lib64
clean:
rm -f *.o
rm -f netPrnctl.so
虽成功生成了动态库,但是在调用时却出现找不到符号的问题,于是使用 ldd -r 查看
neko@neko:~/ZCPrinterDevice/NetworkSetupTool/filter$ ldd -r /usr/lib64/netPrnctl.so
linux-vdso.so.1 (0x00007ffeef44c000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9607add000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f96076ec000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9607f0f000)
undefined symbol: libusb_open (/usr/lib64/netPrnctl.so)
undefined symbol: cupsArrayNew (/usr/lib64/netPrnctl.so)
undefined symbol: cupsDirOpen (/usr/lib64/netPrnctl.so)
undefined symbol: ppdFindAttr (/usr/lib64/netPrnctl.so)
undefined symbol: cupsParseOptions (/usr/lib64/netPrnctl.so)
undefined symbol: cupsGetPPD (/usr/lib64/netPrnctl.so)
undefined symbol: libusb_set_interface_alt_setting (/usr/lib64/netPrnctl.so)
undefined symbol: libusb_release_interface (/usr/lib64/netPrnctl.so)
undefined symbol: ppdClose (/usr/lib64/netPrnctl.so)
undefined symbol: cupsGetOption (/usr/lib64/netPrnctl.so)
undefined symbol: libusb_detach_kernel_driver (/usr/lib64/netPrnctl.so)
undefined symbol: libusb_close (/usr/lib64/netPrnctl.so)
undefined symbol: cupsFreeOptions (/usr/lib64/netPrnc