• Linux·驱动编译相关问题


    一、cc1: error: code model kernel does not support PIC mode
    原因:主机的gcc版本,和开发板的gcc工具版本不一致。需要指定gcc开发板工具的gcc
    解决办法:编写Makefile文件的时候指定gcc工具
        

    Makefile文件中指定gcc如下:

        ifeq ($(HOST), ubuntu)
        #ubuntu内核
        KERNEL_DIR:=/usr/src/linux-headers-$(shell uname -r)
        CC:=gcc
        else
        KERNELDIR:= /home/cw1111/arm_ubuntu/linux-cortexm-2.4.0/linux
        CC:=$(CROSS_COMPILE)gcc    #指定开发板路径上的工具gcc



    二、再次编译模块,出现了问题error: variable ‘__this_module’ has initializer but incomplete type


    原因在编译内核文件时候,在进行配置设置(General setup)的时候,没有勾线Enable loadable module support
    /home/cw1111/GCC/dirver/chardevbase.mod.c:8: error: variable ‘__this_module’ has initializer but incomplete type
    /home/cw1111/GCC/dirver/chardevbase.mod.c:9: error: unknown field ‘name’ specified in initializer
    /home/cw1111/GCC/dirver/chardevbase.mod.c:9: warning: excess elements in struct initializer
    /home/cw1111/GCC/dirver/chardevbase.mod.c:9: warning: (near initialization for ‘__this_module’)
    /home/cw1111/GCC/dirver/chardevbase.mod.c:10: error: unknown field ‘init’ specified in initializer
    /home/cw1111/GCC/dirver/chardevbase.mod.c:10: warning: excess elements in struct initializer
    /home/cw1111/GCC/dirver/chardevbase.mod.c:10: warning: (near initialization for ‘__this_module’)
    /home/cw1111/GCC/dirver/chardevbase.mod.c:14: error: unknown field ‘arch’ specified in initializer
    /home/cw1111/GCC/dirver/chardevbase.mod.c:14: error: ‘MODULE_ARCH_INIT’ undeclared here (not in a function)
    /home/cw1111/GCC/dirver/chardevbase.mod.c:14: warning: excess elements in struct initializer
    /home/cw1111/GCC/dirver/chardevbase.mod.c:14: warning: (near initialization for ‘__this_module’)
    scripts/Makefile.modpost:113: recipe for target ‘/home/cw1111/GCC/dirver/chardevbase.mod.o’ failed…

    解决办法


        执行:make menuconfig
        执行make menuconfig 命令又出现了新的问题
        :0:12: fatal error: curses.h: 没有那个文件或目录
     

    这时因为ubuntu系统中缺少一个套件 ncurses devel ,没有就去下载:
    执行:
    apt-get install libncurses5-dev

    对于 apt-get install libncurses5-dev总是失败的看compiler-gcc5.h源码

        再次执行:make menuconfig 

     

    终于出现了久违的设置框了,选上Enable loadable module support。
    重新编译内核。

    激动人心的时候到了:
    编译我们的驱动文件:make:
    make -C /home/cw1111/arm_ubuntu/linux-cortexm-2.4.0/linux M=/home/cw1111/GCC/dirver modules
    make[1]: 进入目录“/home/cw1111/arm_ubuntu/linux-cortexm-2.4.0/linux”
    CC [M] /home/cw1111/GCC/dirver/chardevbase.o
    Building modules, stage 2.
    MODPOST 1 modules
    CC /home/cw1111/GCC/dirver/chardevbase.mod.o
    LD [M] /home/cw1111/GCC/dirver/chardevbase.ko
    make[1]: 离开目录“/home/cw1111/arm_ubuntu/linux-cortexm-2.4.0/linux”
     

  • 相关阅读:
    编写第一个Go程序
    这几种常见的 JVM 调优场景,你知道吗?
    FFplay文档解读-51-多媒体资源
    技术分享 跨越语言的艺术:Flask Session 伪造
    virtual box安装ubuntu22.04注意事项
    解密C语言选择结构:掌握条件语句与分支逻辑的利器
    【目标检测】SSD损失函数详解
    如何裁剪视频画面尺寸?快把这些方法收好
    100天精通Python(数据分析篇)——第66天:Pandas透视表基础+实战案例(pivot_table函数)
    【小程序】组件化开发的基本使用(二)
  • 原文地址:https://blog.csdn.net/m0_64560763/article/details/126410284