在ubuntu19.04上构建驱动程序模块链接静态库时,为什么会出现警告

时间:2019-11-28 07:37:32

标签: static-libraries kernel-module kbuild

在ubuntu 18.10上,通过链接静态库成功构建了驱动程序模块,而没有发出警告,也成功安装了驱动程序模块。

但是,在ubuntu 19.04上,使用相同的源,通过链接静态库进行构建时会出现警告,并且insmod失败。

警告消息(构建驱动程序模块)

<div class="input-wrap">
    <mat-form-field appearance="outline">
        <mat-label>{{Label}}</mat-label>   
        <input matInput 
            [attr.maxlength] = "MaxLength"
            [value]="Value ? Value : ''"
            [placeholder]="PlaceHolder ? PlaceHolder : ''"
            [readonly]="ReadOnly"
            [ngClass]="NgClass"
            [type]="type ? type: 'text'"
        >
    </mat-form-field>
</div>

错误消息(insmod驱动程序模块)

rm -f *.o *.ko *.o.cmd *.mod.c *.symvers *.cmd
make -C /lib/modules/5.0.0-13-generic/build M=/home/huhao/test_ko modules
make[1]: Entering directory '/usr/src/linux-headers-5.0.0-13-generic'
CC [M] /home/huhao/test_ko/driver.o
LD [M] /home/huhao/test_ko/drv.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: "test" [/home/huhao/test_ko/drv.ko] undefined! -------> This is warning messages
CC /home/huhao/test_ko/drv.mod.o
LD [M] /home/huhao/test_ko/drv.ko
make[1]: Leaving directory '/usr/src/linux-headers-5.0.0-13-generic'

通过在ubuntu19.04上链接静态库来构建驱动程序模块时,为什么会出现警告,但是在ubuntu18.10上却没有警告地构建。

我尝试使用.o文件在ubuntu19.04上构建驱动程序模块,该模块可以构建OK提示警告。

insmod: ERROR: could not insert module drv.ko: Unknown symbol in module

但是我想使用静态库进行链接,该怎么办?

ubuntu18.10信息

drv-y := driver.o lib/libtest.a -> drv-y := driver.o lib/myalib.o

ubuntu19.04信息

kernel Ver. : 4.18.0-10-generic #11
gcc Ver. : gcc version 8.3.0 (Ubuntu 8.3.0-6ubuntu1~18.10.1) 

以下是文件树和源文件

kernel Ver. : 5.0.0-13-generic #14
gcc Ver. : gcc version 8.3.0 (Ubuntu 8.3.0-6ubuntu1) 

[myalib.c]

├── lib
│ ├──myalib.c
│ ├──myalib.h
│ └──Makefile
├── driver.c
└── Makefile

[myalib.h]

int test(void)
{
    return 1 + 2;
}

[Makefile]

extern int test(void);

[driver.c]

# This is the Makefile for creating libtest.a.
RM = rm -f

CCFLAGS = -c
ARFLAG = -rc

CC = gcc
AR = ar

lib_OBJECTS = myalib.o
lib_SOURCE = myalib.c

LIB = libtest.a

libtest.a:$(lib_OBJECTS)
    $(AR) $(ARFLAG) -o $@ $^

$(lib_OBJECTS):$(lib_SOURCE)
    $(CC) $(CCFLAGS) -o $@ $^

clean:
    $(RM) $(lib_OBJECTS)
    $(RM) $(LIB)

[Makefile]

#include <linux/init.h>
#include <linux/module.h>
#include "./lib/myalib.h"

MODULE_LICENSE("Dual BSD/GPL");

int init_module(void)
{
    printk("into init_module."test add = %d.\n", test());
    return 0;
}

void cleanup_module(void)
{
    printk("into cleanup_module.\n");
}

0 个答案:

没有答案
相关问题