how to get the linux kernel version in cpp program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 13
Reputation: scamguru is an unknown quantity at this point 
Solved Threads: 0
scamguru scamguru is offline Offline
Newbie Poster

how to get the linux kernel version in cpp program

 
0
  #1
Apr 15th, 2009
I have a problem like i need to include a different header files depending on the linux kernel in a .cpp file. I have to check the linux kernel version and include the headerfile depending on that kernel. How can I do that?

I have ARCH variable in Makefile which gives me exactly the kernel version, can i make use of that?
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 101
Reputation: PirateTUX is an unknown quantity at this point 
Solved Threads: 3
PirateTUX's Avatar
PirateTUX PirateTUX is offline Offline
Junior Poster

Re: how to get the linux kernel version in cpp program

 
0
  #2
Apr 15th, 2009
I'm going to guess, though I've never done this myself, that you'd do that through preprocessor directives in your source code. I'm thinking it would look something like:

  1. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
  2. #include <whatever_header.h>
  3. #else
  4. #include <a_different_header.h>
  5. #endif

Of course, you'll want to change the version in KERNEL_VERSION, but beyond that it should work.

Check out this post: kernel version in C preprocessor
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC