943,837 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2329
  • C++ RSS
Apr 15th, 2009
0

how to get the linux kernel version in cpp program

Expand Post »
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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
scamguru is offline Offline
13 posts
since Nov 2008
Apr 15th, 2009
0

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

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:

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 17
Solved Threads: 3
Junior Poster
PirateTUX is offline Offline
101 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Colours in Dialog boxes c++
Next Thread in C++ Forum Timeline: Confuse with traverse





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC