文章主要记录一下不常见的错误,供后续开发参考:
日期:2023-05-25 16:31:41
报错:cc1: all warnings being treated as errors
编译条件:
- Ubuntu 18.04,
- 编译器:aarch64-mix210-linux-gcc
- 编译代码:usbip源码,从Linux内核(3.10)复制出来的
错误原因:
- 使用snprintf函数,将最多31个字节写入大小介于0和255之间的区域,这本来只是一个 warning
- 生成Makefile时,加了
-Werror
,将warning当成错误处理解决方案:
- 重新解压源码,使用
grep "Werror" -rnw ./
找到-Werror
的地方,把它删掉,再执行./autogen.sh
。sed 's/-Wall -Werror/-Wall/g' ./configure.ac
错误打印:
usbip_host_driver.c: In function 'usbip_host_export_device':
usbip_host_driver.c:359:45: error: '%s' directive output may be truncated writing up to 31 bytes into a region of size between 0 and 255 [-Werror=format-truncation=]snprintf(attr_path, sizeof(attr_path), "%s/%s:%d.%d/%s",^~
usbip_host_driver.c:359:2: note: 'snprintf' output 7 or more bytes (assuming 293) into a destination of size 256snprintf(attr_path, sizeof(attr_path), "%s/%s:%d.%d/%s",^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~edev->udev.path, edev->udev.busid,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~edev->udev.bConfigurationValue, 0, attr_name);~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Makefile:442: recipe for target 'libusbip_la-usbip_host_driver.lo' failed
make[2]: *** [libusbip_la-usbip_host_driver.lo] Error 1
日期:2023-05-25 16:57:12
报错:编译没出错,运行时缺少动态库,且路径为相对路径./…/…/common/finger…
编译条件:
- Ubuntu 18.04,
- 编译器:aarch64-mix210-linux-gcc,使用arm-hisiv100nptl-linux没出现此情况
- Makefile:CFLAGS += ./…/…/common/finger/lib_himix200/libzaz_himix200_linux.so,使用相对路径的库,但其他库也使用相对路径却不会。
错误原因分析:
运行
aarch64-mix210-linux-objdump -p CK6I_UPPER | grep NEEDED
查看依赖动态库,也是相对路径:
NEEDED libiconv.so.2
NEEDED ./…/…/common/finger/lib_himix200/libzaz_himix200_linux.so猜测是链接时使用相对路径的原因,具体原因不清楚,尝试去掉
解决方案:
- 改Makefile,
-L ./../../common/finger/lib_himix200/ -lzaz_himix200_linux
错误打印:
# ./a.out
./a.out: error while loading shared libraries: ./../../common/finger/lib_himix200/libzaz_himix200_linux.so: cannot open shared object file: No such file or directory