What is the best way to check if I have a 32-bit or a 64-bit Linux?

379 views Asked by At

I have to check in CMake script if I have a 32-bit or a 64-bit Linux in order to know how to build a C++ program. Which command is the best choice :

  • getconf LONG_BIT
  • arch
  • uname -m
2

There are 2 answers

1
sakra On

Using CMake one possible way is to check the CMAKE_SIZEOF_VOID_P variable:

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
    message (STATUS "Compiling for 64-bit")
endif()
0
LiMar On

I'd propose to use any two of the methods together. (or all three)

Just for the backup, and to be cross platform. Another Linux distribution can use another id strings. Or be it ... FreeBSD.

And just to add another method - check architecture of some binary. Like file /usr/bin/gcc.