我想在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
main.c中:
#include <stdio.h> #include "stack.h" int main() { printf("hello"); return 0; }
是否可以configurationCMakeLists.txt来完成我的任务? 我尝试添加一些目录(linux,include,kernel),但是我没有成功。
是的。 但是您将需要编写用于构建内核模块的make文件。
更新1:我推荐QtCreator编写linux内核模块。 看我的手册
更新2:我也推荐eclipse cdt 。 请参阅eclipse 手册,了解如何为Linux内核做准备 。
我用clion来拼写linux内核的方法是:
compile_commands.json
compile_commands.json
转换为适合clion的CMakeLists.txt
这允许代码导航以及合理的编辑体验。