1

I am developing a Linux kernel module (driver) for an embedded system in the Eclipse IDE for C/C++ Linux Developers (Indigo SR2). I have added the kernel's include directory to my project's paths to index (Project > Properties > C/C++ General > Paths and Sybmols -> Includes (tab) -> Add ... (button).) However, several of the kernel's header files refer to the asm dir, which is really an overlay of the linux/asm-powerpc directory (in my case) over the top of the linux/asm-generic directory, where the specific version overrides the generic.

How can I tell Eclipse's indexer to interpret "asm" as "asm-powerpc" first, and if that fails, then look in "asm-generic" second, instead of just looking for "asm"? Symlinking asm-powerpc to asm helps some, but too many header files exist only in the generic location to make this usable.

Thanks!

4

2 回答 2

1

As I have discovered, there are many pieces required to direct Eclipse to index similarly to the kernel build process. However, the answer to this specific question was fairly simple:

Assuming your Linux kernel build directory is defined as ${KDIR}, and your kernel architecture is ${ARCH}, then you need to add the following include paths to your project:

  • ${KDIR}/include
  • ${KDIR}/arch/${ARCH}/include

You can do this in the Project Explorer, by right clicking the project, then Properties > C/C++ General > Paths and Symbols > Includes (tab) > Add ... (button).

I was missing the second entry. Adding it resolved this question. With these 2 entries, checking for unresolved includes (Right click Project > Index > Search for Unresolved Includes) produced 0 errors.

Now I have hit another stumbling block. Some of the types (like, u32 and bool) are still undefined in Eclipse. (My Makefile does not produce any errors.) I believe this is related to some kernel specific variables being undefined in the Eclipse header parsing, causing the include's IFDEF's to not be evaluated the same as during the kernel module compilation. But, I have not resolved this yet, and that pertains to another question. :)

于 2012-05-05T03:27:23.933 回答
1

Instead of adding the paths per project, one can also add global environment variables to Eclipse CDT. For Eclipse Kepler, in Window > Preferences > C/C++ > Build > Environment, add variables:

  • C_INCLUDE_PATH = /usr/include/c++/${gcc-version}
  • CPLUS_INCLUDE_PATH = /usr/include:${KDIR}/include:${KDIR}/include/linux:${KDIR}/arch/${ARCH}/include

Replace ${var} above with real entries, e.g. replace ${gcc-version} with 4.6.3. Then restart Eclipse and variables should be properly resolved. For Kernel module development these are probably enough.

If one needs to read the whole Kernel source, read this link: http://wiki.eclipse.org/HowTo_use_the_CDT_to_navigate_Linux_kernel_source

于 2014-05-27T09:48:00.847 回答