对__kmalloc的未定义引用

问题描述 投票:0回答:2

虽然使用SCTP内核标头<sctp/chunk.h>的编译代码我遇到了令人困惑的编译器错误(蓝色文本,而不是读取的),但该错误由调用kmalloc函数(其原型在<linux/slob-def.h>中定义)触发。这是导致它的函数:

/* Allocate and initialize datamsg. */
SCTP_STATIC struct sctp_datamsg *sctp_datamsg_new(gfp_t gfp)
{
    struct sctp_datamsg *msg;
    msg = kmalloc(sizeof(struct sctp_datamsg), gfp);
    if (msg) {
        sctp_datamsg_init(msg);
        SCTP_DBG_OBJCNT_INC(datamsg);
    }
    return msg;
}

gcc错误消息(在本机C中编译):

/tmp/ccKDKVjf.o: In function `sctp_datamsg_new':
s.c:(.text+0x2215): undefined reference to `__kmalloc'
collect2: error: ld returned 1 exit status

所以我想知道kmalloc函数源代码是否正确定义(或根本没有实际实现,或者调用此函数的代码只能在内核模式下编译。我实际上并未尝试构建一个输出文件,但我在Emacs中发出的编译命令是:gcc s.c(其中s.c是包含.c标头的<sctp/chunk.h>文件-只是在尝试确保所有文件都能正确编译之后再构建输出文件) )。

c linux-kernel ld
2个回答
2
投票

1
投票
© www.soinside.com 2019 - 2024. All rights reserved.