我试图从硅实验室编译这个UART -> USB 司机。它只在Ubuntu版本18.04 (Bionic)上进行了测试,我的机器正在21.10 (Impish)上运行。显然,其中一个不同之处在于,最新版本允许在构建内核模块时进行严格的指针转换检查:
/lib/-r/$(uname -r)/build/Makefile
# enforce correct pointer usage
KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)我想知道是否有一种方法可以禁用特定的标志,因为它阻止我编译驱动程序。我知道错误:
.../vcp_driver_source/Linux_3.x.x_4.x.x_VCP_Driver_Source/cp210x.c:290:35: error: initialization of ‘void (*)(struct usb_serial_port *)’ from incompatible pointer type ‘int (*)(struct usb_serial_port *)’ [-Werror=incompatible-pointer-types]
290 | .port_remove = cp210x_port_remove,
| ^~~~~~~~~~~~~~~~~~
.../vcp_driver_source/Linux_3.x.x_4.x.x_VCP_Driver_Source/cp210x.c:290:35: note: (near initialization for ‘cp210x_device.port_remove’)
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:277: .../vcp_driver_source/Linux_3.x.x_4.x.x_VCP_Driver_Source/cp210x.o] Error 1
make[1]: *** [Makefile:1874: .../vcp_driver_source/Linux_3.x.x_4.x.x_VCP_Driver_Source] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.15.23-76051523-generic'
make: *** [Makefile:7: all] Error 2Makefile非常简单,我可以根据需要修改它。
Makefile
obj-m = cp210x.o
KDIR = /lib/modules/`uname -r`/build
SRCDIR = $(PWD)
# try this instead if you don't have PWD defined
# SRCDIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
all:
$(MAKE) -C $(KDIR) M=$(SRCDIR) modules
clean:
$(MAKE) -C $(KDIR) M=$(SRCDIR) clean发布于 2022-02-28 20:32:14
将以下内容添加到makefile顶部,解决了这个问题
ccflags-y := -Wno-error=incompatible-pointer-types从linux内核文档上我找到了
-- 3.7汇编旗帜 这三个标志只适用于分配它们的。它们用于递归构建过程中发生的所有普通cc、as和ld调用。注意:具有相同行为的标志以前被命名为: EXTRA_CFLAGS、EXTRA_AFLAGS和EXTRA_LDFLAGS。他们仍然被支持,但他们的使用是不可取的。 指定使用$(CC)编译的选项。 示例: $( := ) += -DACPI_DEBUG_OUTPUT 这个变量是必需的,因为顶部Makefile拥有变量$(KBUILD_CFLAGS),并将其用于整个树的编译标志。
之后就是找到正确的gcc旗的问题。谢天谢地,gcc提供了一种用-Wno-error解除-Wno-error标志的方法。设置,该设置覆盖默认行为,并允许编译不出现问题。
https://stackoverflow.com/questions/71300360
复制相似问题