如何为 linux 驱动程序和内核开发准备 QTCreator
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5417732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Howto prepare QTCreator for linux driver & kernel development
提问by camelord
i tried a few IDEs on linux to develop driver in C. QtCreator suits best for me. I need the IDE just for the intellisence (codecompletion, jump to functions on click.. etc.) for quicker coding.
我在 linux 上尝试了一些 IDE 来用 C 开发驱动程序。 QtCreator 最适合我。我需要 IDE 只是为了智能(代码完成,点击时跳转到功能......等)以更快地编码。
Has anyone configured QTCreator for such needs. E.g. what do i have to do to get intellisence for a struct?
有没有人为这种需求配置过 QTCreator。例如,我必须做什么才能获得结构的智能?
regards camelord.
问候骆驼主。
回答by Karatheodory
回答by Steven Kenny
A better solution is to import the linux source with "Import Existing Project". Add all the files your ARCH requires. Once created edit the .includes file and remove all the include dirs listed.
更好的解决方案是使用“导入现有项目”导入 linux 源代码。添加您的 ARCH 所需的所有文件。创建后编辑 .includes 文件并删除列出的所有包含目录。
Then just add the few that linux uses.
然后只需添加linux使用的几个。
include
arch/<ARCH>/include
arch/<ARCH>/mach-<MACH>/include
arch/<ARCH>/<PLATFORM>/include
Now edit .config, this is the best bit. Add something like the following.
现在编辑.config,这是最好的一点。添加如下内容。
#define __KERNEL__
#define __arm__
#define __LINUX_ARM_ARCH__ 7
#include <linux/kconfig.h>
It's the #include that brings in all of the autoconf stuff you mostly want.
#include 引入了您最想要的所有 autoconf 内容。
Do a make V=1 to see the standard defines that the Kernel build uses.
执行 make V=1 以查看内核构建使用的标准定义。
Also if you're using a cross compiler, set up as usual in "Build & Run" Compilers tab.
此外,如果您使用的是交叉编译器,请在“构建和运行”编译器选项卡中照常设置。
回答by RedEyed
I have the same problem. I found a solution, how to prepare Qt Creator to the linux Kernel development in the Ubuntu.
我也有同样的问题。我找到了一个解决方案,如何在 Ubuntu 中为 linux Kernel 开发准备 Qt Creator。
Prepare include paths:
准备包含路径:
- Create Non-Qt project (Plan C-Project).
- Add your files to project.
- Download your linux-headers. On Ubuntu 14.04
sudo apt-get install linux-headers-$(uname -r)
Configuring your *.pro file:
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt ARCH=arm64 SRC_PROJECT_PATH = /home/user/my_LKM_project LINUX_HEADERS_PATH = /usr/src/linux-headers-$$system(uname -r) SOURCES += $$system(find -L $$SRC_PROJECT_PATH -type f -name "*.c" -o -name "*.S" ) HEADERS += $$system(find -L $$SRC_PROJECT_PATH -type f -name "*.h" ) OTHER_FILES += $$system(find -L $$SRC_PROJECT_PATH -type f -not -name "*.h" -not -name "*.c" -not -name "*.S" ) INCLUDEPATH += $$system(find -L $$SRC_PROJECT_PATH -type d) INCLUDEPATH += $$system(find -L $$LINUX_HEADERS_PATH/include -type d) INCLUDEPATH += $$system(find -L $$LINUX_HEADERS_PATH/arch/$$ARCH/include -type d)
- 创建非 Qt 项目(Plan C-Project)。
- 将您的文件添加到项目中。
- 下载你的 linux 头文件。在 Ubuntu 14.04 上
sudo apt-get install linux-headers-$(uname -r)
配置您的 *.pro 文件:
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt ARCH=arm64 SRC_PROJECT_PATH = /home/user/my_LKM_project LINUX_HEADERS_PATH = /usr/src/linux-headers-$$system(uname -r) SOURCES += $$system(find -L $$SRC_PROJECT_PATH -type f -name "*.c" -o -name "*.S" ) HEADERS += $$system(find -L $$SRC_PROJECT_PATH -type f -name "*.h" ) OTHER_FILES += $$system(find -L $$SRC_PROJECT_PATH -type f -not -name "*.h" -not -name "*.c" -not -name "*.S" ) INCLUDEPATH += $$system(find -L $$SRC_PROJECT_PATH -type d) INCLUDEPATH += $$system(find -L $$LINUX_HEADERS_PATH/include -type d) INCLUDEPATH += $$system(find -L $$LINUX_HEADERS_PATH/arch/$$ARCH/include -type d)
Building:
建筑:
- Create Makefile
- In the Qt Creator go to the "Projects" and unset the "Shadow build"
- In the "Build Steps" remove all items and add "make" item. In the make item in the first field set make, in the second field set command for your Makefile.
Also you can set your build script.
- 创建 Makefile
- 在 Qt Creator 中,转到“项目”并取消设置“阴影构建”
- 在“构建步骤”中删除所有项目并添加“制作”项目。在第一个字段中的 make 项中设置 make,在第二个字段中为你的 Makefile 设置命令。
您也可以设置构建脚本。
回答by StMartin81
I'm not allowed to comment, so I'll add a comment here to RedEyed's answer. I had to escape the quotes, otherwise I got an error message from the find command:
我不允许发表评论,因此我将在此处为 RedEyed 的回答添加评论。我不得不转义引号,否则我会从 find 命令中收到一条错误消息:
SOURCES += $$system(find -L $$SRC_PROJECT_PATH -type f -name \"*.c\" -o -name \"*.S\" )