2

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
vir2al
  • 817
  • 4
  • 11
  • 15

2 Answers2

3

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()
sakra
  • 62,199
  • 16
  • 168
  • 151
  • This is good but according to the documentation CMAKE_SIZEOF_VOID is fetched by using the compiler, so this would indicate 32bit if you are on a 64-bit and compiling for 32-bits, notably with "-m32". – thoni56 Apr 12 '17 at 10:10
1

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.

LiMar
  • 2,822
  • 3
  • 22
  • 28