我正在尝试使用makefile从C源代码构建串行USB驱动程序,但是当我键入sudo make或sudo make install时,输出就像;
sudo make
gcc -Wall -D__KERNEL__ -DMODULE -I / lib / modules / 4.15.0-45-generic / build / include -D__SMP__ -DSMP -I / usr / src / linux-4.15.0-45-generic / drivers / usb / serial / -O -c- o ftdi_sio.o ftdi_sio.c在包含的文件中 /lib/modules/4.15.0-45-generic/build/include/linux/kernel.h:7:0, 来自ftdi_sio.c:251:/lib/modules/4.15.0-45-generic/build/include/linux/linkage.h:8:25: 致命的
错误:asm / linkage.h:没有这样的文件或目录
编译终止。 :目标“ ftdi_sio.o”的配方 制作失败:*** [ftdi_sio.o]错误1
我知道asm / linkage.h文件不在include / linux目录中。问题是,如何更改给定头文件的目录或如何将头文件替换为给定目录。我也欢迎其他解决方案。 Makefile和Rules.make文件是;
Rules.make:
# -*-makefile-*-
#
# This file is part of the sample code for the book "Linux Device Drivers",
# second edition. It is meant to be generic and is designed to be recycled
# by other drivers. The comments should be clear enough.
# It partly comes from Linux Makefile, and needs GNU make. <rubini@linux.it>
# TOPDIR is declared by the Makefile including this file.
ifndef TOPDIR
TOPDIR = .
endif
# KERNELDIR can be speficied on the command line or environment
ifndef KERNELDIR
KERNELDIR := $(shell echo "/lib/modules/`uname -r`/build")
endif
# The headers are taken from the kernel
INCLUDEDIR = $(KERNELDIR)/include
# We need the configuration file, for CONFIG_SMP and possibly other stuff
# (especiall for RISC platforms, where CFLAGS depends on the exact
# processor being used).
ifeq ($(KERNELDIR)/.config,$(wildcard $(KERNELDIR))/.config)
include $(KERNELDIR)/.config
else
MESSAGE := $(shell echo "WARNING: no .config file in $(KERNELDIR)")
endif
# ARCH can be speficed on the comdline or env. too, and defaults to this arch
# Unfortunately, we can't easily extract if from kernel configuration
# (well, we could look athe asm- symlink... don't know if worth the effort)
ifndef ARCH
ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
-e s/arm.*/arm/ -e s/sa110/arm/)
endif
# This is useful if cross-compiling. Taken from kernel Makefile (CC changed)
AS =$(CROSS_COMPILE)as
LD =$(CROSS_COMPILE)ld
CC =$(CROSS_COMPILE)gcc
CPP =$(CC) -E
AR =$(CROSS_COMPILE)ar
NM =$(CROSS_COMPILE)nm
STRIP =$(CROSS_COMPILE)strip
OBJCOPY =$(CROSS_COMPILE)objcopy
OBJDUMP =$(CROSS_COMPILE)objdump
# The platform-specific Makefiles include portability nightmares.
# Some platforms, though, don't have one, so check for existence first
ARCHMAKEFILE = $(TOPDIR)/Makefile.$(ARCH)
ifeq ($(ARCHMAKEFILE),$(wildcard $(ARCHMAKEFILE)))
include $(ARCHMAKEFILE)
endif
USBDI=/linux
# CFLAGS: all assignments to CFLAGS are inclremental, so you can specify
# the initial flags on the command line or environment, if needed.
CFLAGS += -Wall -D__KERNEL__ -DMODULE -I$(INCLUDEDIR)
ifdef CONFIG_SMP
CFLAGS += -D__SMP__ -DSMP
endif
# Prepend modversions.h if we're running with versioning.
ifdef CONFIG_MODVERSIONS
CFLAGS += -DMODVERSIONS -include $(KERNELDIR)/include/linux/modversions.h
endif
#Install dir
VERSIONFILE = $(INCLUDEDIR)/linux/version.h
VERSION = $(shell awk -F\" '/REL/ {print $$2}' $(VERSIONFILE))
INSTALLDIR = /lib/modules/$(VERSION)/misc
Makefile:
# This Makefile has been simplified as much as possible, by putting all
# generic material, independent of this specific directory, into
# ../Rules.make. Read that file for details
# The usb serial headers
INCLUDEUSBSER := $(shell echo "/usr/src/linux-`uname -r`/drivers/usb/serial/")
TOPDIR := $(shell pwd)
#TOPDIR = .
include $(TOPDIR)/Rules.make
CFLAGS += -I$(INCLUDEUSBSER) -O
OBJS = ftdi.o
all: $(OBJS)
ftdi.o: ftdi_sio.o
$(LD) -r $^ -o $@
install:
install -d $(INSTALLDIR)
install -c $(OBJS) $(INSTALLDIR)
clean:
rm -f *.o *~ core
我也有ftdi_sio.c文件和ftdi.sio.h文件,我认为这不受此问题的限制。