如何为 Linux 驱动程序准备 QTCreator内核开发

发布于 2024-10-26 06:50:58 字数 157 浏览 3 评论 0原文

我在Linux上尝试了一些IDE来用C语言开发驱动程序。QtCreator最适合我。 我需要 IDE 只是为了智能(代码完成、点击跳转到函数等)以加快编码速度。

有没有人配置 QTCreator 来满足这样的需求。 例如,我必须做什么才能获得结构的智能?

问候 驼主。

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.

Has anyone configured QTCreator for such needs.
E.g. what do i have to do to get intellisence for a struct?

regards
camelord.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

凡尘雨 2024-11-02 06:50:58

更好的解决方案是使用“Import Existing Project”导入linux源。
添加 ARCH 所需的所有文件。
创建后,编辑 .includes 文件并删除列出的所有包含目录。

然后添加linux使用的几个就可以了。

include
arch/<ARCH>/include
arch/<ARCH>/mach-<MACH>/include
arch/<ARCH>/<PLATFORM>/include

现在编辑.config,这是最好的部分。
添加如下内容。

#define __KERNEL__
#define __arm__
#define __LINUX_ARM_ARCH__ 7

#include <linux/kconfig.h>

#include 引入了您最想要的所有 autoconf 内容。

执行 make V=1 以查看内核构建使用的标准定义。

此外,如果您使用交叉编译器,请像往常一样在“构建和运行”编译器选项卡中进行设置。

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.

Then just add the few that linux uses.

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.

#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.

Do a make V=1 to see the standard defines that the Kernel build uses.

Also if you're using a cross compiler, set up as usual in "Build & Run" Compilers tab.

策马西风 2024-11-02 06:50:58

我有同样的问题。
我找到了一个解决方案,如何在Ubuntu上准备Qt Creator进行linux Kernel开发。

准备包含路径

  1. 创建非 Qt 项目(计划 C 项目)。
  2. 将您的文件添加到项目中。
  3. 下载你的 linux-headers。在 Ubuntu 14.04 上 sudo apt-get install linux-headers-$(uname -r)
  4. 配置您的 *.pro 文件:

    <前><代码>模板 = 应用程序
    配置+=控制台
    配置-=app_bundle
    配置-= 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)

构建:

  1. 创建 Makefile
  2. 在 Qt Creator 中,转到“Projects”并取消设置“Shadow build”,
  3. 在“Build Steps”中删除所有项目并添加“make”项目。在第一个字段中的 make 项中设置 make,在第二个字段中为 Makefile 设置命令。
    您还可以设置构建脚本。

I have the same problem.
I found a solution, how to prepare Qt Creator to the linux Kernel development in the Ubuntu.

Prepare include paths:

  1. Create Non-Qt project (Plan C-Project).
  2. Add your files to project.
  3. Download your linux-headers. On Ubuntu 14.04 sudo apt-get install linux-headers-$(uname -r)
  4. 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)
    

Building:

  1. Create Makefile
  2. In the Qt Creator go to the "Projects" and unset the "Shadow build"
  3. 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.
剪不断理还乱 2024-11-02 06:50:58

我在此处找到了答案。要完成此任务,您需要添加

QMAKE_CXXFLAGS = -I/usr/src/linux-3.1.8-1-ARCH/include
QMAKE_CFLAGS = -I/usr/src/linux-3.1.8-1-ARCH/include

到用于构建内核模块的所有 .pro 文件。

I found answer here. To acomplish this you need to add

QMAKE_CXXFLAGS = -I/usr/src/linux-3.1.8-1-ARCH/include
QMAKE_CFLAGS = -I/usr/src/linux-3.1.8-1-ARCH/include

to all .pro files that are used for building kernel modules.

冬天旳寂寞 2024-11-02 06:50:58

我不被允许发表评论,所以我会在 RedEyed 的答案中添加评论。我必须转义引号,否则我会从 find 命令收到错误消息:

SOURCES += $system(find -L $SRC_PROJECT_PATH -type f -name \"*.c\" -o -name \"*.S\" )

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:

SOURCES += $system(find -L $SRC_PROJECT_PATH -type f -name \"*.c\" -o -name \"*.S\" )
时光无声 2024-11-02 06:50:58

另一种选择是:

  1. 照常构建 Linux 内核,但具有详细输出: make KBUILD_VERBOSE=1 | tee build.log
  2. 使用 此存储库中的 prepare_kernel_project.py (脚本采用 build.log 并解析上一步中用于构建的文件/选项,然后创建 QtCreator 项目):
~/linux$ git clone https://github.com/TheMeaningfulEngineer/linux-in-qtcreator.git
~/linux$ cp linux-in-qtcreator/prepare_kernel_project.py .
~/linux$ chmod 755 prepare_kernel_project.py
~/linux$ ./prepare_kernel_project.py build.log linux
  1. 最后,在 QtCreator 中打开项目: 文件->打开文件或项目 -> linux/linux.creator

PS 来源

Another option is to:

  1. build linux kernel as usual, but with verbose output: make KBUILD_VERBOSE=1 | tee build.log
  2. Use prepare_kernel_project.py from this repo (the script takes build.log and parses files/options used for building in the previous step, and then creates QtCreator project):
~/linux$ git clone https://github.com/TheMeaningfulEngineer/linux-in-qtcreator.git
~/linux$ cp linux-in-qtcreator/prepare_kernel_project.py .
~/linux$ chmod 755 prepare_kernel_project.py
~/linux$ ./prepare_kernel_project.py build.log linux
  1. And finally, open the project in QtCreator: File -> Open File or Project -> linux/linux.creator

P.S. Source

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文