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

自作多情 提交于 2019-12-24 03:06:04

问题


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

回答1:


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()



回答2:


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.



来源:https://stackoverflow.com/questions/20630257/what-is-the-best-way-to-check-if-i-have-a-32-bit-or-a-64-bit-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!