4

如何判断CPU 架构和操作系统类型

 1 year ago
source link: https://charon-cheung.github.io/2023/06/27/C++/C++%20%20%E5%9F%BA%E7%A1%80/%E5%A6%82%E4%BD%95%E5%88%A4%E6%96%ADCPU%20%E6%9E%B6%E6%9E%84%E5%92%8C%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%B1%BB%E5%9E%8B/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

如何判断CPU 架构和操作系统类型

如何判断CPU 架构和操作系统类型
2023-06-27|C++C++ 基础|
Word count: 155|Reading time: 1 min
#include<iostream>

int main()
{
#if defined __linux__
std::cout<<"linux system"<<std::endl;
#elif defined _WIN32
std::cout<<"windows system"<<std::endl;
#endif

#if defined __aarch64__
std::cout<<"this is arm cpu"<<std::endl;
#elif defined __x86_64__
std::cout<<"this id x86 cpu"<<std::endl;
#endif
return 0;
}

cmake 中判断CPU 架构,操作系统类型

cmake_minimum_required(VERSION 3.10.0)

message(${CMAKE_HOST_SYSTEM_NAME})
message(${CMAKE_HOST_SYSTEM_PROCESSOR})

if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
message("this is Linux")
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
message("this is Windows")
endif()
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
message("this is aarch64 cpu")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
message("this is x86_64 cpu")
endif()

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK