Inconsistency detected by ld.so: dl-deps.c: 622: _dl_map_object_deps: Assertion `nlist > 1’ failed! 的一种解决方法
情景描述
在arm开发板上编写智能卡通信程序,需要动态链接PC/SC库libpcsclite.so。在Ubuntu上使用arm-none-linux-gnueabi-gcc交叉编译,makefile内容如下:
## Makefile
CROSS_COMPILE=arm-none-linux-gnueabi-
CC=$(CROSS_COMPILE)gcc
PCSC_PATH=/home/ljl/pcsc
LIBS=-L${PCSC_PATH}/lib/ -lpcsclite
INCLUDES=-I. -I${PCSC_PATH}/include/PCSC/
TARGET=target
all:
$(CC) -o $(TARGET) target.c $(LIBS) -ldl $(INCLUDES)
chmod +x $(TARGET)
clean:
rm $(TARGET) 2>/dev/null
其中,$(CC) -o $(TARGET) target.c $(LIBS) $(INCLUDES)
一行命令完成编译、链接的全过程,直接生成可执行文件target。$(INCLUDES)指定libpcsclite.so的头文件winscard.h等的存放路径,$(LIBS)指定libpcsclite.so的存放路径。
make 编译通过,运行时报错:Inconsistency detected by ld.so: dl-deps.c: 622: _dl_map_object_deps: Assertion `nlist > 1’ failed!
编译通过,运行时导入动态库异常。
解决方法
把$(INCLUDES)放到$(LIBS)前面:
$(CC) -o $(TARGET) target.c $(INCLUDES) $(LIBS) -ldl
注意事项
运行时会动态链接libpcsclite.so,因此在运行前需要export LD_LIBRARY_PATH,指定libpcsclite.so在开发板上的存放位置:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/root/pcsc/
lib/
否则会报错:
error while loading shared libraries: libpcsclite.so.1: cannot open shared object file: No such file or directory