Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using linux header files in visual studio

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.

like image 209
Peter Hwang Avatar asked Feb 15 '23 18:02

Peter Hwang


2 Answers

#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

like image 67
Motes Avatar answered Feb 26 '23 20:02

Motes


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

like image 33
Calchas Avatar answered Feb 26 '23 20:02

Calchas