是否可以在CLion中开发linux内核模块?

Den*_*nis 11 c linux cmake linux-kernel clion

我想在CLion中开发一些小的Linux内核模块.例如,我想编译这些文件:

stack.h:

#ifndef _LL_STACK_H
#define _LL_STACK_H
#include <linux/list.h>

typedef struct stack_entry {
    struct list_head lh;
    void *data;
} stack_entry_t;

stack_entry_t* create_stack_entry(void *data);
void delete_stack_entry(stack_entry_t *entry);

void stack_push(struct list_head *stack, stack_entry_t *entry);
stack_entry_t* stack_pop(struct list_head *stack);
#define stack_empty(stack) list_empty((stack))

#define STACK_DATA(stack_entry, data_ptr_type) \
    ((data_ptr_type)(stack_entry)->data)

#define STACK_DATA_RESET(stack_entry, new_data) \
    do { \
        (stack_entry)->data = new_data; \
    } while(0)

#endif //_LL_STACK_H
Run Code Online (Sandbox Code Playgroud)

main.c中:

#include <stdio.h>
#include "stack.h"

int main() {
    printf("hello");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

是否可以配置CMakeLists.txt来完成我的任务?我尝试添加一些目录(linux,include,kernel),但我没有成功.

Red*_*yed 7

是的.但是您需要编写make文件来构建内核模块.

更新1: 我建议QtCreator编写linux内核模块.看我的手册

更新2: 我也推荐eclipse cdt.请参阅eclipse 手册,了解如何为linux内核做好准备.