Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "HowTo use the CDT to navigate Linux kernel source"

(GCC v8+: Fix internal gcc freestanding headers resolution)
(Migrated to GitHub)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
+
{{warning|Note: The contents of this page has been migrated. Please see https://github.com/eclipse-cdt/cdt/tree/main/FAQ#whats-the-best-way-to-set-up-the-cdt-to-navigate-linux-kernel-source for current information, or page history for historical versions. }}
''Disclaimer: These steps were last updated for Eclipse 2019‑03, CDT 9.7.0, and Linux v5.1-rc4
+
 
+
#Download and install Eclipse plus the CDT.
+
#Configure and build your kernel to define CONFIG_* and generate autoconf.h. This can be done before or after downloading and installing Eclipse.
+
#Ensure that you have the right kernel source (e.g. make sure you are on the right git branch).  If you check out another branch later, that's ok, but you will need to re-index the source, which can take a big amount of time.
+
#Start up Eclipse.
+
#Click '''File''' -> '''New''' -> '''Project'''
+
#In the pop-up window, choose '''C/C++'''-> '''C Project'''. Click '''Next'''
+
#Fill in a project name like ''Linux v5.1''
+
#Uncheck the '''Use default location''' box and type in the root directory of your kernel into the '''Location''' box.
+
#In the '''Project type:''' pane, click the '''Makefile project''' and select '''Empty Project'''
+
#On the right side, select '''Linux GCC'''. Click '''Next'''
+
#Click '''Advanced settings...''' and a Properties dialog will pop up.
+
# Note: At this point, and starting from Eclipse Oxygen, Eclipse will aggressively start indexing your project, which can make Eclipse painfully slow for the rest of the configuration steps below -- especially if the desire is to only index a small relevant part of the kernel. To mitigate that, temporarily disable indexing now by opening '''C/C++ General''' section, click on '''Indexer''', click on '''Enable project-specific settings''', then unmark the '''Enable indexer''' option.
+
#Open the '''C/C++ General''' selection on the left.
+
#Click on '''Preprocessor Include Paths'''
+
#Select '''GNU C''' in the '''Languages''' list
+
#Select '''CDT User Setting Entries''' in the '''Setting Entries''' list
+
#Click on '''Add...'''. Choose '''Preprocessor Macros File''' from the top left dropdown, '''Project Path''' from the top right dropdown, and enter "{{Code|include/linux/kconfig.h}}" into the '''File''' text box. Note 1: For older kernels (e.g. 4.1.12, 4.2.7, or less), selecting "{{Code|include/generated/autoconf.h}}" works better. In newer kernels, selecting {{Code|kconfig.h}} is better as this file includes <generated/autoconf.h> and also makes sure that tests such as IS_ENABLED(option) are correctly expanded by the CDT scanner. Note 2: For kernels older than 2.6.33, the location of autoconf.h is {{Code|include/linux/autoconf.h}}
+
#Also add any other macros files you are using.
+
#Click on '''Indexer'''
+
#Checkmark the '''Enable project specific setttings''' box.
+
#Uncheck '''Index source files not included in the build'''
+
#Click on '''Paths and Symbols''' on the left.
+
#Select the '''Includes''' tab and then select '''GNU C'''
+
#Click '''Add...'''
+
#Click '''Workspace...''' then select your kernel's {{Code|include}}, and {{Code|include/uapi}} directories
+
#Do another Add, Workspace and add both {{Code|arch/}}''architecture''{{Code|/include}}, and {{Code|arch/}}''architecture''{{Code|/include/uapi}} directories. e.g., {{Code|arch/powerpc/include}} and {{Code|arch/powerpc/include/uapi}} (The UAPI directories are due to the kernel's user/kernel header split covered [http://lwn.net/Articles/507794/ here] in-detail)
+
#Click the '''# Symbols''' tab
+
#Click '''Add...'''
+
#Set the name to {{Code|__KERNEL__}}
+
#Set the value to {{Code|1}} and click '''OK'''
+
#Click the '''Source Location''' tab
+
#Click the plus sign (or arrow/triangle) next to your project name.
+
#Select the '''Filter''' item and click '''Edit Filter...'''
+
#Click '''Add Multiple...''' and then select all of the {{Code|arch/*}} directories in your kernel source that will not be used (i.e. all the ones that are not for the architecture you are using)
+
#Click '''OK''' and '''OK''' again to dismiss that dialog.
+
#Under '''C/C++ General''', select '''Preprocessor Include Paths, Macros etc.'''
+
#Click the '''Providers''' tab and select '''CDT GCC Built-in Compiler Settings'''
+
#Uncheck '''Use global provider shared between projects
+
#Append {{Code|-nostdinc}} to the curretly-existing '''Command to get compiler specs'''. The kernel is a ''free-standing'' environment by ISO C99 definition. That is, it does not want to be polluted, and obviously cannot work with, the "host" header files and libraries.
+
#Open a terminal, and type "echo -iwithprefix $(gcc --print-file-name include/)". Append ''the resulting output'' to the '''Command to get compiler specs''' mentioned above. Rationale is, {{Code|-nostdinc}} asked gcc to ''not'' search the standard system directories for header files. But the Linux Kernel depends on GCC-provided "freestanding environment" headers like ''stdarg.h'', ''stdbool.h'', etc., and which are typically hosted by GCC under ''/lib/gcc/<arch>/<version>/include''. Thus the append.
+
#Check '''Allocate console in the Console View''' so you can see that this is working
+
#Click '''OK''' on the Properties dialog.
+
#Note: If you temporarily disabled indexing as earlier recommended. This is the right time to re-enable it. Under '''C/C++ General''', click on '''Indexer''', and mark the '''Enable indexer''' option.
+
#Click '''Finish''' on the C Project dialog.
+
#The Project will index automatically.
+
#On a platter drive indexing will take upwards of 20 minutes to complete, on a SSD indexing will take about 5 minutes to complete.
+
 
+
 
+
Authored and continuously updated, from Linux v2.6.33 to Linux v5.1, by:
+
 
+
* Ahmed S. Darwish [mailto:darwish.07@gmail.com darwish.07@gmail.com]
+
 
+
 
+
Based on earlier work by:
+
 
+
* Corey Ashford [mailto:cjashfor@us.ibm.com cjashfor@us.ibm.com]
+
* Adam Duskett [mailto:Aduskett@gmail.com Aduskett@gmail.com]
+

Latest revision as of 11:05, 9 November 2022

Warning2.png
Note: The contents of this page has been migrated. Please see https://github.com/eclipse-cdt/cdt/tree/main/FAQ#whats-the-best-way-to-set-up-the-cdt-to-navigate-linux-kernel-source for current information, or page history for historical versions.

Back to the top