问题
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