how to get the linux kernel version in cpp program
-
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, can i make use of that? :omg:
-
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, can i make use of that? :omg:
Best way it to first include keranal version.h file in your project (ex:"/usr/include/linux/version.h"), and then put below checks in your code.
#if RHEL_MAJOR == 5
#include "xyx_5.h"
#else
#include "xyx.h"
#endif
Parag Patel Sr. Software Eng, Varaha Systems
-
Best way it to first include keranal version.h file in your project (ex:"/usr/include/linux/version.h"), and then put below checks in your code.
#if RHEL_MAJOR == 5
#include "xyx_5.h"
#else
#include "xyx.h"
#endif
Parag Patel Sr. Software Eng, Varaha Systems
lOOKS LIKE this doesn't work for me. I saw the version.h file, it has got 3 lines as below. #define UTS_RELEASE "2.4.20" #define LINUX_VERSION_CODE 132116 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) And I want to differentiate kernels for 2.4 and 2.6. Is the above code still works with it.I've placed my code as below, but it seems not working. #include "/usr/include/linux/version.h" #if RHEL_MAJOR=2.4.20 #include "../../build/i686-Linux-2.4.32/ReleaseVersion.hh" #else #include "../../build/i686-Linux-2.6.21/ReleaseVersion.hh" #endif What went wrong in my case. Thanks in advance :wtf:
-
lOOKS LIKE this doesn't work for me. I saw the version.h file, it has got 3 lines as below. #define UTS_RELEASE "2.4.20" #define LINUX_VERSION_CODE 132116 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) And I want to differentiate kernels for 2.4 and 2.6. Is the above code still works with it.I've placed my code as below, but it seems not working. #include "/usr/include/linux/version.h" #if RHEL_MAJOR=2.4.20 #include "../../build/i686-Linux-2.4.32/ReleaseVersion.hh" #else #include "../../build/i686-Linux-2.6.21/ReleaseVersion.hh" #endif What went wrong in my case. Thanks in advance :wtf:
Try below code,
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,0)
//include for version 2.4 or lower
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
//include for version 2.6 or higer
#endif // 2.4
#endif //2.6Parag Patel Sr. Software Eng, Varaha Systems
-
Try below code,
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,0)
//include for version 2.4 or lower
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
//include for version 2.6 or higer
#endif // 2.4
#endif //2.6Parag Patel Sr. Software Eng, Varaha Systems