Xilinx PetaLinux 工具链交叉编译xilinx_axidma源码出现stdlib.h No such file or directory问题的调查

文章详细记录了在使用XilinxPetaLinux工具链编译xilinx_axidma源码时遇到stdlib.h文件未找到的错误,通过对环境配置文件、makefile的分析,发现是由于xilinx_axidma的makefile中CC变量覆盖了PetaLinux的环境配置。通过注释掉该变量,成功解决了编译问题,最终完成编译并生成了库文件和示例程序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Xilinx PetaLinux 工具链交叉编译xilinx_axidma源码出现stdlib.h No such file or directory问题的调查

Petalinux工具链编译xilinx_axidma报错:

ubuntu@ubuntu:~/worksapce/xilinx_axidma$ make examples
outputs
arm-xilinx-linux-gnueabi-
arm-xilinx-linux-gnueabi-gcc -Wall -Wextra -Werror -std=gnu99 -g -O0 -fPIC -shared -Wno-missing-field-initializers -I include library/libaxidma.c -o library/libaxidma.so
library/libaxidma.c:13:10: fatal error: stdlib.h: No such file or directory
   13 | #include <stdlib.h>
      |          ^~~~~~~~~~
compilation terminated.
library/library.mk:53: recipe for target 'library/libaxidma.so' failed
make: *** [library/libaxidma.so] Error 1
ubuntu@ubuntu:~/worksapce/xilinx_axidma$

分析原因 1 (/opt/petalinux/2020.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi)环境配置问题:

# Check for LD_LIBRARY_PATH being set, which can break SDK and generally is a bad practice

# http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN80

# http://xahlee.info/UnixResource_dir/_/ldpath.html

# Only disable this check if you are absolutely know what you are doing!

if [ ! -z "$LD_LIBRARY_PATH" ]; then
    echo "Your environment is misconfigured, you probably need to 'unset LD_LIBRARY_PATH'"
    echo "but please check why this was set in the first place and that it's safe to unset."
    echo "The SDK will not operate correctly in most cases when LD_LIBRARY_PATH is set."
    echo "For more references see:"
    echo "  http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN80"
    echo "  http://xahlee.info/UnixResource_dir/_/ldpath.html"
    return 1
fi
export SDKTARGETSYSROOT=/opt/petalinux/2020.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi
export PATH=/opt/petalinux/2020.2/sysroots/x86_64-petalinux-linux/usr/bin:/opt/petalinux/2020.2/sysroots/x86_64-petalinux-linux/usr/sbin:/opt/petalinux/2020.2/sysroots/x86_64-petalinux-linux/bin:/opt/petalinux/2020.2/sysroots/x86_64-petalinux-linux/sbin:/opt/petalinux/2020.2/sysroots/x86_64-petalinux-linux/usr/bin/../x86_64-petalinux-linux/bin:/opt/petalinux/2020.2/sysroots/x86_64-petalinux-linux/usr/bin/arm-xilinx-linux-gnueabi:/opt/petalinux/2020.2/sysroots/x86_64-petalinux-linux/usr/bin/arm-xilinx-linux-musl:$PATH
export PKG_CONFIG_SYSROOT_DIR=$SDKTARGETSYSROOT
export PKG_CONFIG_PATH=$SDKTARGETSYSROOT/usr/lib/pkgconfig:$SDKTARGETSYSROOT/usr/share/pkgconfig
export CONFIG_SITE=/opt/petalinux/2020.2/site-config-cortexa9t2hf-neon-xilinx-linux-gnueabi
export OECORE_NATIVE_SYSROOT="/opt/petalinux/2020.2/sysroots/x86_64-petalinux-linux"
export OECORE_TARGET_SYSROOT="$SDKTARGETSYSROOT"
export OECORE_ACLOCAL_OPTS="-I /opt/petalinux/2020.2/sysroots/x86_64-petalinux-linux/usr/share/aclocal"
export OECORE_BASELIB="lib"
export OECORE_TARGET_ARCH="arm"
export OECORE_TARGET_OS="linux-gnueabi"
unset command_not_found_handle
export CC="arm-xilinx-linux-gnueabi-gcc  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export CXX="arm-xilinx-linux-gnueabi-g++  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export CPP="arm-xilinx-linux-gnueabi-gcc -E  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export AS="arm-xilinx-linux-gnueabi-as "
export LD="arm-xilinx-linux-gnueabi-ld  --sysroot=$SDKTARGETSYSROOT"
export GDB=arm-xilinx-linux-gnueabi-gdb
export STRIP=arm-xilinx-linux-gnueabi-strip
export RANLIB=arm-xilinx-linux-gnueabi-ranlib
export OBJCOPY=arm-xilinx-linux-gnueabi-objcopy
export OBJDUMP=arm-xilinx-linux-gnueabi-objdump
export READELF=arm-xilinx-linux-gnueabi-readelf
export AR=arm-xilinx-linux-gnueabi-ar
export NM=arm-xilinx-linux-gnueabi-nm
export M4=m4
export TARGET_PREFIX=arm-xilinx-linux-gnueabi-
export CONFIGURE_FLAGS="--target=arm-xilinx-linux-gnueabi --host=arm-xilinx-linux-gnueabi --build=x86_64-linux --with-libtool-sysroot=$SDKTARGETSYSROOT"
export CFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types "
export CXXFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types "
export LDFLAGS="-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed"
export CPPFLAGS=""
export KCFLAGS="--sysroot=$SDKTARGETSYSROOT"
export OECORE_DISTRO_VERSION="2020.2"
export OECORE_SDK_VERSION="2020.2"
export ARCH=arm
export CROSS_COMPILE=arm-xilinx-linux-gnueabi-

# Append environment subscripts

if [ -d "$OECORE_TARGET_SYSROOT/environment-setup.d" ]; then
    for envfile in $OECORE_TARGET_SYSROOT/environment-setup.d/*.sh; do
	    . $envfile
    done
fi
if [ -d "$OECORE_NATIVE_SYSROOT/environment-setup.d" ]; then
    for envfile in $OECORE_NATIVE_SYSROOT/environment-setup.d/*.sh; do
	    . $envfile
    done
fi
export CLANGCC="arm-xilinx-linux-gnueabi-clang  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -mlittle-endian --sysroot=$SDKTARGETSYSROOT"
export CLANGCXX="arm-xilinx-linux-gnueabi-clang++  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -mlittle-endian --sysroot=$SDKTARGETSYSROOT"
export CLANGCPP="arm-xilinx-linux-gnueabi-clang -E  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -mlittle-endian --sysroot=$SDKTARGETSYSROOT"
export CLANG_TIDY_EXE="arm-xilinx-linux-gnueabi-clang-tidy  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -mlittle-endian --sysroot=$SDKTARGETSYSROOT"

通过在xilinx_axidma侧的makefile打印消息(添加library_echo消息打印标签):

# library.mk

#

# Date: July 28, 2016

# Author: Brandon Perez

# Author: Jared Choi

#

# The Makefile for building the AXI DMA library.

# Include guard for the Makefile

ifndef LIBAXIDMA_MAKEFILE_
LIBAXIDMA_MAKEFILE_=included

################################################################################

# Configuration

################################################################################

# The flags for compiling the library

LIBAXIDMA_CFLAGS = $(GLOBAL_CFLAGS) -fPIC -shared \
				   -Wno-missing-field-initializers

# The files that makeup the AXI DMA library

LIBAXIDMA_DIR = library
LIBAXIDMA_FILES = libaxidma.c
LIBAXIDMA = $(addprefix $(LIBAXIDMA_DIR)/,$(LIBAXIDMA_FILES))

# The header files for the AXI DMA library interface

LIBAXIDMA_INC_DIRS = include
LIBAXIDMA_INC_FILES = libaxidma.h axidma_ioctl.h
LIBAXIDMA_INC = $(addprefix $(LIBAXIDMA_INC_DIRS)/,$(LIBAXIDMA_INC_FILES))
LIBAXIDMA_INC_FLAGS = $(addprefix -I ,$(LIBAXIDMA_INC_DIRS))

# The shared library files generated by compilation

LIBAXIDMA_NAME = axidma
LIBAXIDMA_LIBRARY = $(LIBAXIDMA_DIR)/lib$(LIBAXIDMA_NAME).so
LIBAXIDMA_OUTPUT_LIBRARY = $(OUTPUT_DIR)/lib$(LIBAXIDMA_NAME).so

# The Doxygen configuration file and generated libaxidma documentation file

LIBAXIDMA_DOC_CONFIG = libaxidma.dox
LIBAXIDMA_DOC = $(DOC_DIR)/html/index.html

################################################################################

# Targets

################################################################################

.PHONY: library library library_docs library_echo library_clean


# User-facing targets for compiling the library

library: $(LIBAXIDMA_OUTPUT_LIBRARY)

# Compile the library into a shared library file

$(LIBAXIDMA_LIBRARY): $(LIBAXIDMA) $(LIBAXIDMA_INC) | cross_compiler_check
	$(CC) $(LIBAXIDMA_CFLAGS) $(LIBAXIDMA_INC_FLAGS) $(filter %.c,$^) -o $@

# Copy the compiled shared library object to the specified output directory

$(LIBAXIDMA_OUTPUT_LIBRARY): $(LIBAXIDMA_LIBRARY) $(OUTPUT_DIR)
	@cp $< $@

# Geneate the Doxygen documentation for the library

library_docs:
	doxygen $(LIBAXIDMA_DOC_CONFIG) &> /dev/null
	firefox $(LIBAXIDMA_DOC) &

library_echo:
	@echo "echo LIBAXIDMA_OUTPUT_LIBRARY!"
	@echo $(LIBAXIDMA_OUTPUT_LIBRARY)
	@echo $(GLOBAL_CFLAGS)
	@echo $(LIBAXIDMA_CFLAGS)
	@echo $(LIBAXIDMA)
	@echo $(LIBAXIDMA_INC)
	@echo $(LIBAXIDMA_INC_FLAGS)
	@echo $(CC)
	@echo $(KCFLAGS)

# Clean up all the files generated by compiling the library

library_clean:
	rm -f $(LIBAXIDMA_OUTPUT_LIBRARY) $(LIBAXIDMA_LIBRARY)

endif # LIBAXIDMA_MAKEFILE_

打印结果各个环境变量均正确,于是进行后续调查。

分析原因 2 (/home/ubuntu/worksapce/xilinx_axidma/config.mk)环境配置问题:

添加交叉编译配置变量重新编译:

# Makefile Configuration Template

#

# This file is a template for the 'config.mk' file, which stores the

# values of variables used in the Makefile. This can be used instead of

# specifying the variables on the command line, which can quickly become

# cumbersome.

#

# To make use of this functionality, copy this file to 'config.mk', and then

# fill in the values as desired. Any of these variables can be overridden from

# the command line, so the variables are not permanent.

# TODO: Copy this file to 'config.mk' and uncomment and assign the variables

################################################################################

# Cross Compilation Options

################################################################################

# This controls the cross compiler that is used to compile all of the code. This

# should be a compiler prefix (e.g. `arm-linux-gnueabihf-`). The code will be

# compiled with the program `$(CROSS_COMPILE)gcc`

CROSS_COMPILE = arm-xilinx-linux-gnueabi-

# This variable informs the kernel Makefile what architecture you're targeting.

# This is required when building the driver, if CROSS_COMPILE is defined.

ARCH = arm

################################################################################

# Build Options

################################################################################

# The path to the top-level directory of kernel source tree that you want to

# compile the driver against. If unspecified, the system default

# `/lib/modules/$(uname -r)/build` is used. If CROSS_COMPILE is defined, then

# this variable must also be defined. This path can be absolute, or relative.

KBUILD_DIR = /home/ubuntu/worksapce/kernel-driver/linux-xlnx-xlnx_rebase_v5.4_2020.2

# The path to the output directory, where all of the compiled files, the

# driver's kernel object, the example executables, and the AXI DMA shared

# library file are placed. If unspecified, the files are stored in `outputs` in

# the top level of the repository. This path can either be relative or absolute.

OUTPUT_DIR = outputs

# This specifies to fixup the path that the file `xilinx_dma.h` is located at in

# the kernel that you're compiling against. The location of this header file was

# changed between the 3.x and 4.x Xilinx kernel versions. However, some 4.x

# kernels still have the file at the old location. This variable specifies the

# Makefile to define a macro that fixes this issue. Uncomment this (no value is

# required), if the driver fails to compile with an error like:

#     `fatal error: linux/dma/xilinx_dma.h: No such file or directory`

XILINX_DMA_INCLUDE_PATH_FIXUP = yes

重新编译发现报错依然存在,于是进行后续调查

分析原因 3 Petalinux工具链和xilinx_axidma测的环境配置出现冲突:

着重调查交叉编译根目录的配置(sysroot)

在/opt/petalinux/2020.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi侧:

export CC="arm-xilinx-linux-gnueabi-gcc  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export CXX="arm-xilinx-linux-gnueabi-g++  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=$SDKTARGETSYSROOT"

而在xilinx_axidma的makefile:

# Allow the user to specify cross-compilation from the command line
CC = $(CROSS_COMPILE)gcc

由此发现了CC在xilinx_axidma的makefile被覆盖petalinux中配置的环境被破坏,调查至此结束,注释掉ilinx_axidma的makefile中的CC环境变量,编译通过:

# Makefile

#

# Date: March 5, 2016

# Author: Brandon Perez

# Author: Jared Choi

#

# The top-level Makefile for the project, handles compilation for both the

# driver and the example application programs

# Include the user defined variables, if they specified them

-include config.mk

################################################################################

# Configuration

################################################################################

#INC=-I/opt/petalinux/2020.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi/usr/include

# Set the shell to BASH

SHELL = /bin/bash

# Allow the user to specify cross-compilation from the command line

#CC = $(CROSS_COMPILE)gcc

# Standard gcc flags for compilation

GLOBAL_CFLAGS = -Wall -Wextra -Werror -std=gnu99 -g -O0

# The location where the compiled executables and driver will be stored

OUTPUT_DIR ?= outputs

# The location where the generated documentation files are stored

DOC_DIR = docs

################################################################################

# Targets

################################################################################

# None of the targets correspond to actual files

.PHONY: all docs clean cross_compiler_check help

# Compile the driver, library, and examples in release mode as the default

all: driver library examples

# Generate the doxygen documentation for library

docs: library_docs

# Include the specific targets for the examples, library, and driver (the

# includes must go here, so the default target is 'all')

include library/library.mk
include driver/driver.mk
include examples/examples.mk

# Make the specified output directory, if it doesn't exist

$(OUTPUT_DIR):
	@mkdir -p $(OUTPUT_DIR)

# Clean up all temporary files

clean: driver_clean examples_clean library_clean
	rm -rf $(OUTPUT_DIR)

# Check that the specified cross-compiler exists

cross_compiler_check:
	$(info, "here add the debug info")
	$(warning, "here add the debug info")
	@echo $(OUTPUT_DIR)
#$(error "error: this will stop the compile")
ifdef CROSS_COMPILE
ifeq (,$(shell which $(CC)))
	@printf "Error: '$(CROSS_COMPILE)' is not a valid cross-compiler prefix. "
	@printf "'$(CC)' was not found in your path.\n"
	@exit 1
endif
endif
	@echo $(CROSS_COMPILE)

# Display a help message to the user

help:
	@printf "Usage:\n"
	@printf "\tmake [target] [variable] ...\n"
	@printf "\n"
	@printf "Targets:\n"
	@printf "\tall (default)\n"
	@printf "\t    The default target. Compiles all components.\n"
	@printf "\n"
	@printf "\tdocs\n"
	@printf "\t    Generates the Doxygen documentation all of the components.\n"
	@printf "\n"
	@printf "\tclean\n"
	@printf "\t    Cleans up all intermediate files generated by compilation\n"
	@printf "\t    of the driver and example programs.\n"
	@printf "\n"
	@printf "\tdriver\n"
	@printf "\t    Compiles the AXI DMA driver. The kernel object file can be\n"
	@printf "\t    found at '\$$(OUTPUT_DIR)/axidma.ko'.\n"
	@printf "\n"
	@printf "\tdriver_clean\n"
	@printf "\t    Cleans up files generated by the driver's compilation.\n"
	@printf "\n"
	@printf "\tlibrary\n"
	@printf "\t    Compiles the AXI DMA library. The shared library file can\n"
	@printf "\t    be found at '\$$(OUTPUT_DIR)/libaxidma.so'.\n"
	@printf "\n"
	@printf "\tlibrary_docs\n"
	@printf "\t    Generates the Doxygen documentation for the library as\n"
	@printf "\t    both as HTML and Latex. These can be found under 'docs'.\n"
	@printf "\t    Also, opens the HTML documentation in firefox.\n"
	@printf "\n"
	@printf "\tlibrary_clean\n"
	@printf "\t    Cleans up the files generated by compiling the library.\n"
	@printf "\n"
	@printf "\texamples, <example_name>\n"
	@printf "\t    Compiles the example programs or specific example program.\n"
	@printf "\t    The executable for a given example can be found at\n"
	@printf "\t    '\$$(OUTPUT_DIR)/<example name>'.\n"
	@printf "\n"
	@printf "\texamples_clean\n"
	@printf "\t    Cleans up files generated by compiling the examples.\n"
	@printf "\n"
	@printf "\thelp\n"
	@printf "\t    Display this help message.\n"
	@printf "\n"
	@printf "Variables:\n"
	@printf "\tThe variables can be specified either on the command line or\n"
	@printf "\tin 'config.mk'. See 'config_template.mk' for a template of the\n"
	@printf "\tMakefile configuration file and more detailed explanations.\n"
	@printf "\n"
	@printf "\tCROSS_COMPILE\n"
	@printf "\t    The prefix for the cross compiler to use for compilation.\n"
	@printf "\t    For example, \`arm-linux-gnueabi-\`. Not required; if left\n"
	@printf "\t    unspecified, then the system default compiler is used.\n"
	@printf "\n"
	@printf "\tARCH\n"
	@printf "\t    The architecture that the code is being compiled for.\n"
	@printf "\t    Only needed when cross-compiling the driver.\n"
	@printf "\n"
	@printf "\tKBUILD_DIR\n"
	@printf "\t    The path to the kernel source tree to build the driver\n"
	@printf "\t    against. Required when cross-compiling the driver.\n"
	@printf "\t    Otherwise, may be left unspecified. If it is, the system\n"
	@printf "\t    default is used.\n"
	@printf "\n"
	@printf "\tOUTPUT_DIR\n"
	@printf "\t    The path where the generated code files (both the kernel \n"
	@printf "\t    object file and executables) will be stored. The default \n"
	@printf "\t    is the "outputs" in the top-level directory.\n"
	@printf "\n"
	@printf "\tXILINX_DMA_INCLUDE_PATH_FIXUP\n"
	@printf "\t    Specifies to fix and issue with the location of the header\n"
	@printf "\t    file 'xilinx_dma.h' in the kernel you're compiling against\n"
	@printf "\t    Specify if you see an include error when compiling.\n"
	@printf "\n"
	@printf "Examples:\n"
	@printf "\tmake\n"
	@printf "\tmake CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm "
	@printf "KBUILD_DIR=/home/kernels/linux/ driver\n"
	@printf "\tmake CROSS_COMPILE=arm-linux-gnueabihf- OUTPUT_DIR=outputs "
	@printf "examples\n"
	@printf "\tmake axidma_benchmark\n"
	@printf "\tmake OUTPUT_DIR=outputs clean\n"

最后编译结果:

ubuntu@ubuntu:~/worksapce/xilinx_axidma$ make library_echo 
echo LIBAXIDMA_OUTPUT_LIBRARY!
outputs/libaxidma.so
-Wall -Wextra -Werror -std=gnu99 -g -O0
-Wall -Wextra -Werror -std=gnu99 -g -O0 -fPIC -shared -Wno-missing-field-initializers
library/libaxidma.c
include/libaxidma.h include/axidma_ioctl.h
-I include
arm-xilinx-linux-gnueabi-gcc
--sysroot=/opt/petalinux/2020.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ make library_echo 
echo LIBAXIDMA_OUTPUT_LIBRARY!
outputs/libaxidma.so
-Wall -Wextra -Werror -std=gnu99 -g -O0
-Wall -Wextra -Werror -std=gnu99 -g -O0 -fPIC -shared -Wno-missing-field-initializers
library/libaxidma.c
include/libaxidma.h include/axidma_ioctl.h
-I include
arm-xilinx-linux-gnueabi-gcc -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/petalinux/2020.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi
--sysroot=/opt/petalinux/2020.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ make library
arm-xilinx-linux-gnueabi-gcc  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/petalinux/2020.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi -Wall -Wextra -Werror -std=gnu99 -g -O0 -fPIC -shared -Wno-missing-field-initializers -I include library/libaxidma.c -o library/libaxidma.so
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ make examples
arm-xilinx-linux-gnueabi-gcc  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/petalinux/2020.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi -Wall -Wextra -Werror -std=gnu99 -g -O0 -I include examples/axidma_benchmark.c examples/util.c -o examples/axidma_benchmark \
	-L outputs -l axidma -Wl,-rpath,'$ORIGIN'
arm-xilinx-linux-gnueabi-gcc  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/petalinux/2020.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi -Wall -Wextra -Werror -std=gnu99 -g -O0 -I include examples/axidma_display_image.c examples/util.c -o examples/axidma_display_image \
	-L outputs -l axidma -Wl,-rpath,'$ORIGIN'
arm-xilinx-linux-gnueabi-gcc  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/petalinux/2020.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi -Wall -Wextra -Werror -std=gnu99 -g -O0 -I include examples/axidma_transfer.c examples/util.c -o examples/axidma_transfer \
	-L outputs -l axidma -Wl,-rpath,'$ORIGIN'
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ make driver
make -C /home/ubuntu/worksapce/kernel-driver/linux-xlnx-xlnx_rebase_v5.4_2020.2 M=/home/ubuntu/worksapce/xilinx_axidma/driver modules
make[1]: Entering directory '/home/ubuntu/worksapce/kernel-driver/linux-xlnx-xlnx_rebase_v5.4_2020.2'
  CC [M]  /home/ubuntu/worksapce/xilinx_axidma/driver/axi_dma.o
  CC [M]  /home/ubuntu/worksapce/xilinx_axidma/driver/axidma_chrdev.o
  CC [M]  /home/ubuntu/worksapce/xilinx_axidma/driver/axidma_dma.o
  CC [M]  /home/ubuntu/worksapce/xilinx_axidma/driver/axidma_of.o
  LD [M]  /home/ubuntu/worksapce/xilinx_axidma/driver/axidma.o
  Building modules, stage 2.
  MODPOST 1 modules
  LD [M]  /home/ubuntu/worksapce/xilinx_axidma/driver/axidma.ko
make[1]: Leaving directory '/home/ubuntu/worksapce/kernel-driver/linux-xlnx-xlnx_rebase_v5.4_2020.2'
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ 
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ ll
total 172
drwxrwxrwx 7 ubuntu ubuntu   4096 Jun 29 01:56 ./
drwxrwxr-x 5 ubuntu ubuntu   4096 Jun 27 01:54 ../
-rwxrwxrwx 1 ubuntu ubuntu   2704 Jun 28 20:27 config.mk*
-rwxrwxrwx 1 ubuntu ubuntu   2600 Nov 19  2018 config_template.mk*
drwxrwxrwx 2 ubuntu ubuntu   4096 Jun 29 01:56 driver/
drwxrwxrwx 2 ubuntu ubuntu   4096 Jun 29 01:56 examples/
-rwxrwxrwx 1 ubuntu ubuntu    690 Nov 19  2018 .gitignore*
drwxrwxrwx 2 ubuntu ubuntu   4096 Jun 27 00:37 include/
-rwxrwxrwx 1 ubuntu ubuntu 100312 Nov 19  2018 libaxidma.dox*
drwxrwxrwx 2 ubuntu ubuntu   4096 Jun 29 01:56 library/
-rwxrwxrwx 1 ubuntu ubuntu   1171 Nov 19  2018 LICENSE*
-rwxrwxrwx 1 ubuntu ubuntu   5707 Jun 29 01:56 Makefile*
drwxrwxr-x 2 ubuntu ubuntu   4096 Jun 28 20:27 outputs/
-rwxrwxrwx 1 ubuntu ubuntu  15787 Nov 19  2018 README.md*
-rwxrwxrwx 1 ubuntu ubuntu    987 Nov 19  2018 .travis.yml*
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ ll outputs/
total 624
drwxrwxr-x 2 ubuntu ubuntu   4096 Jun 28 20:27 ./
drwxrwxrwx 7 ubuntu ubuntu   4096 Jun 29 01:56 ../
-rwxrwxr-x 1 ubuntu ubuntu  30916 Jun 29 01:56 axidma_benchmark*
-rwxrwxr-x 1 ubuntu ubuntu  28296 Jun 29 01:56 axidma_display_image*
-rw-rw-r-- 1 ubuntu ubuntu 511792 Jun 29 01:56 axidma.ko
-rwxrwxr-x 1 ubuntu ubuntu  27384 Jun 29 01:56 axidma_transfer*
-rwxrwxr-x 1 ubuntu ubuntu  25276 Jun 29 01:56 libaxidma.so*
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ 

在编译过程中遇到 `No such file or directory` 错误通常意味着编译器无法找到所需的头文件或库文件。此类错误可能由多种原因引起,包括缺少依赖库、路径配置错误、交叉编译环境设置不当等。以下是一些常见的解决方法: ### 1. 确认所需文件是否确实存在 首先应检查报错中提到的文件是否存在于系统中。可以使用 `find` 或 `locate` 命令进行查找,例如: ```bash find / -name stdlib.h 2>/dev/null ``` 如果找不到该文件,可能是缺少相应的开发包或库。此时需要安装缺失的依赖项。 ### 2. 安装缺失的开发包 对于标准库头文件(如 `stdlib.h`、`openssl/opensslv.h` 等),通常需要安装对应的开发包。例如,在基于 Debian 的系统上: ```bash sudo apt-get install libc6-dev ``` 在基于 Red Hat 的系统上: ```bash sudo yum install glibc-headers ``` 如果是 OpenSSL 相关的头文件缺失,可安装 OpenSSL 开发包: ```bash sudo apt-get install libssl-dev # Debian/Ubuntu sudo yum install openssl-devel # Red Hat/CentOS ``` 这些操作可解决因缺少标准头文件而导致的编译错误 [^1]。 ### 3. 检查交叉编译环境配置 在使用 Xilinx PetaLinux 工具链进行交叉编译时,可能出现路径配置错误或环境变量未正确设置的问题。例如,`stdlib.h` 找不到可能是因为未正确加载工具链环境变量。可通过以下命令加载环境: ```bash source /opt/petalinux/2020.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi ``` 确保编译时使用的交叉编译器路径正确,并且目标架构的头文件路径已包含在编译命令中,例如使用 `-I` 参数指定头文件搜索路径: ```bash gcc -I/path/to/include -o myapp myapp.c ``` 此外,检查项目中的 `config.mk` 文件是否配置了正确的交叉编译器和头文件路径 [^2]。 ### 4. 处理特定头文件缺失问题 某些头文件如 `stropts.h` 可能并不存在于现代 Linux 系统中,但某些旧版软件仍依赖它。此时可以手动创建该文件,内容如下: ```c /* stropts.h - fake for old applications */ #ifndef _SYS_STROPTS_H #define _SYS_STROPTS_H 1 #include <sys/ioctl.h> #endif ``` 将其放置在编译器查找路径中(如 `/usr/include/sys/stropts.h`),即可绕过此类错误 [^3]。 ### 5. 检查内核头文件路径 若在编译内核模块时遇到 `linux/module.h: No such file or directory` 错误,应确保已安装内核源码包,并正确设置内核头文件路径。例如: ```bash sudo apt install linux-headers-$(uname -r) ``` 然后在编译时指定内核源码路径: ```bash make -C /lib/modules/$(uname -r)/build M=$(PWD) modules ``` 这可确保编译器找到所需的内核头文件 [^4]。 ### 6. 使用包管理器修复依赖问题 如果错误源于依赖项未满足,可使用包管理器尝试修复。例如,在 Debian/Ubuntu 系统上: ```bash sudo apt-get install -f ``` 此命令会尝试修复损坏的依赖关系,自动安装缺失的依赖项 [^5]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值