camelord
camelord

Reputation: 101

Howto prepare QTCreator for linux driver & kernel development

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.

Upvotes: 10

Views: 13362

Answers (5)

DimanNe
DimanNe

Reputation: 1931

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

Upvotes: 0

StMartin81
StMartin81

Reputation: 41

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\" )

Upvotes: 0

RedEyed
RedEyed

Reputation: 2135

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.

Upvotes: 7

Steven Kenny
Steven Kenny

Reputation: 81

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.

Upvotes: 8

Karatheodory
Karatheodory

Reputation: 945

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.

Upvotes: 3

Related Questions