Question

I was trying to use linux kernel header file on the visual studio 2013. I want to do this for auto completion purpose.

I noticed that stdio.h file is inside of the C:\Program Files\Visual Studio 12.0\VC\crt\src, So I copied my linux folder, which contains kernel header files, into the src folder. However, Visual studio does not seem to find these header files.

For example: #include <linux/kernel.h>

It says Error: cannot open source file "linux/kernel.h"

I tried to change all slash characters into back slash, however, it does not fix the issue. What do I have to do if I want to make visual studio know this header file is existed?

I know I could move my kernel.h to my current folder and use #include "kernel.h"

However, I would like to keep the system header files in my computer and use with #include <linux/kernel.h> when it is needed.

Was it helpful?

Solution

#include <kernel.h>

and add C:\Program Files\Visual Studio 12.0\VC\crt\src\linux to the include path (if one is using VS2017 which shipped with it).

To obtain the kernel.h file, i.e. kernel source, determine the kernel version one needs and obtain the src from kernel.org, e.g. 5.4.26

OTHER TIPS

In Visual Studio 2015, the alternative is to install the Visual C++ for Linux Development and the Visual C++ for Android Development templates. At time of writing the Linux headers are only present in the Android development folder, on my machine it was C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r10e\platforms\android-21\arch-x86_64\usr\include. Add that path to the include path and Intellisense works for common Linux files like <sys/socket.h>.

Current location(s) under VS 2017 with Android files in a separate tree, 32 and 64 bit:

C:\Microsoft\AndroidNDK{,64}\android-ndk-r{NDK_VER}c\platforms\android-{P_VER}\arch-x86{,_64}\usr\include

NDK_VER -- versions of the NDK, currently 12,13,15  
P_VER   -- target android platform version (aka level), currently the highest is 26

Examples:

C:\Microsoft\AndroidNDK\android-ndk-r15c\platforms\android-26\arch-x86\usr\include C:\Microsoft\AndroidNDK\android-ndk-r15c\platforms\android-26\arch-x86_64\usr\include C:\Microsoft\AndroidNDK64\android-ndk-r15c\platforms\android-26\arch-x86\usr\include C:\Microsoft\AndroidNDK64\android-ndk-r15c\platforms\android-26\arch-x86_64\usr\include

This reflects general "new style" in VS with build platforms and target platforms being separated and orthogonal. There are also arch-{arm,mips}{,64} so 6 folders under arch target platform version.

Include files are the same in AndroidNDK and AndroidNDK64 and under one NDK version only files under machine and asm folders are different (for Intel and Mips even files under asm are identical for 32 and 64 bits).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top