cmake:CMAKE_SYSTEM_PROCESSOR为空是怎么回事儿?

本文详细解析了在使用CMake进行交叉编译时,CMAKE_SYSTEM_NAME和CMAKE_SYSTEM_PROCESSOR参数的重要性。若仅设置CMAKE_SYSTEM_NAME而忽略CMAKE_SYSTEM_PROCESSOR,会导致后者值为空的错误。文章通过实例演示正确配置方法。

今天执行cmake创建Makefile的时候出了个怪事:CMAKE_SYSTEM_PROCESSOR的值为空
反复测试到到了原因:我在执行cmake时加了参数-DCMAKE_SYSTEM_NAME=Linux

cmake  . -G "Eclipse CDT4 - Unix Makefiles"  -DCMAKE_SYSTEM_NAME=Linux

根据cmake官方关于交叉编译的介绍: 《Cross Compiling for Linux》,CMAKE_SYSTEM_NAMECMAKE_SYSTEM_PROCESSOR是交叉编译的时候必须指定的两个参数。

所以如果在cmake命令行定义了CMAKE_SYSTEM_NAME,就必须也定义CMAKE_SYSTEM_PROCESSOR,如下。

cmake  . -G "Eclipse CDT4 - Unix Makefiles"  \
	-DCMAKE_SYSTEM_NAME=Linux \
	-DCMAKE_SYSTEM_PROCESSOR=x86_64

如果在命令行只是定义了CMAKE_SYSTEM_NAME,就会出现CMAKE_SYSTEM_PROCESSOR为空这种奇怪的问题。

另外经测试如果在CMakeLists.txt脚本中用set命令设置CMAKE_SYSTEM_NAME的值,并不会影响CMAKE_SYSTEM_PROCESSOR的值:

set(CMAKE_SYSTEM_NAME Linux)
CMake编译时FFMPEG一直显示Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.26100. CMake Warning (dev) at D:/CMake/share/cmake-4.0/Modules/Platform/Windows-MSVC.cmake:556 (enable_language): project() should be called prior to this enable_language() call. Call Stack (most recent call first): D:/CMake/share/cmake-4.0/Modules/Platform/Windows-MSVC.cmake:529 (__windows_compiler_msvc_enable_rc) D:/CMake/share/cmake-4.0/Modules/Platform/Windows-MSVC-CXX.cmake:6 (__windows_compiler_msvc) D:/CMake/share/cmake-4.0/Modules/CMakeCXXInformation.cmake:48 (include) CMakeLists.txt:107 (enable_language) This warning is for project developers. Use -Wno-dev to suppress it. CMake Warning (dev) at D:/CMake/share/cmake-4.0/Modules/Platform/Windows-MSVC.cmake:556 (enable_language): project() should be called prior to this enable_language() call. Call Stack (most recent call first): D:/CMake/share/cmake-4.0/Modules/Platform/Windows-MSVC.cmake:529 (__windows_compiler_msvc_enable_rc) D:/CMake/share/cmake-4.0/Modules/Platform/Windows-MSVC-C.cmake:5 (__windows_compiler_msvc) D:/CMake/share/cmake-4.0/Modules/CMakeCInformation.cmake:48 (include) CMakeLists.txt:107 (enable_language) This warning is for project developers. Use -Wno-dev to suppress it. Detected processor: AMD64 CMake Warning at cmake/OpenCVDetectCXXCompiler.cmake:177 (message): OpenCV does not recognize MSVC_VERSION "1943". Cannot set OpenCV_RUNTIME Call Stack (most recent call first): CMakeLists.txt:161 (include) CMake Warning at cmake/OpenCVUtils.cmake:758 (message): Unexpected option: WITH_CUFFT (=ON) Condition: IF (WITH_CUDA) Call Stack (most recent call first): CMakeLists.txt:251 (OCV_OPTION) CMake Warning at cmake/OpenCVUtils.cmake:758 (message): Unexpected option: WITH_CUBLAS (=ON) Condition: IF (WITH_CUDA) Call Stack (most recent call first): CMakeLists.txt:254 (OCV_OPTION) CMake Warning at cmake/OpenCVUtils.cmake:758 (message): Unexpected option: WITH_CUDNN (=ON) Condition: IF (WITH_CUDA) Call Stack (most recent call first): CMakeLists.txt:257 (OCV_OPTION)0K
05-12
我都告诉你再E:\Libs里面 为什么你还要重新安装 OpenBLAS?你到底再干什么啊?我虚拟环境都不见了!!!!!”PS C:\Users\Administrator\Desktop> cd E:\PyTorch_Build\pytorch PS E:\PyTorch_Build\pytorch> python -m venv rtx5070_env No pyvenv.cfg file PS E:\PyTorch_Build\pytorch> .\rtx5070_env\Scripts\activate ParserError: E:\PyTorch_Build\pytorch\rtx5070_env\Scripts\activate.ps1:9 Line | 9 | if () { | ~ | Missing condition in if statement after 'if ('. PS E:\PyTorch_Build\pytorch> # 修复激活脚本 PS E:\PyTorch_Build\pytorch> $activateContent = @" >> # E:\PyTorch_Build\pytorch\rtx5070_env\Scripts\activate.ps1 >> param() >> >> # 设置环境变量 >> $env:VIRTUAL_ENV = "E:\PyTorch_Build\pytorch\rtx5070_env" >> $env:PATH = "E:\PyTorch_Build\pytorch\rtx5070_env\Scripts;" + $env:PATH >> >> # 移除旧的环境变量(如果存在) >> if ($env:_OLD_VIRTUAL_PATH) { >> $env:PATH = $env:_OLD_VIRTUAL_PATH >> } >> >> # 保存当前 PATH >> $env:_OLD_VIRTUAL_PATH = $env:PATH >> >> Write-Host "✅ 虚拟环境已激活: $env:VIRTUAL_ENV" -ForegroundColor Green >> "@ PS E:\PyTorch_Build\pytorch> PS E:\PyTorch_Build\pytorch> $activateContent | Out-File "E:\PyTorch_Build\pytorch\rtx5070_env\Scripts\activate.ps1" -Encoding UTF8 -Force PS E:\PyTorch_Build\pytorch> # 修改 CMake 配置以支持 AMD64 PS E:\PyTorch_Build\pytorch> $qnnpackPath = "E:\PyTorch_Build\pytorch\aten\src\ATen\native\quantized\cpu\qnnpack\CMakeLists.txt" PS E:\PyTorch_Build\pytorch> (Get-Content $qnnpackPath) -replace >> "if\(CMAKE_SYSTEM_PROCESSOR MATCHES \"\^(i\[3-6]86\|x86_64\|amd64\)\$\"\)", >> 'if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i[3-6]86|x86_64|amd64|AMD64)$")' | >> Set-Content $qnnpackPath ParserError: Line | 2 | "if\(CMAKE_SYSTEM_PROCESSOR MATCHES \"\^(i\[3-6]86\|x86_64\|amd64 … | ~~ | Unexpected token '\^' in expression or statement. PS E:\PyTorch_Build\pytorch> PS E:\PyTorch_Build\pytorch> Write-Host "✅ 已修复 AMD64 处理器识别问题" ✅ 已修复 AMD64 处理器识别问题 PS E:\PyTorch_Build\pytorch> # 添加 CUDA 环境变量 PS E:\PyTorch_Build\pytorch> $env:CUDA_PATH = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0" PS E:\PyTorch_Build\pytorch> $env:PATH = "$env:CUDA_PATH\bin;$env:PATH" PS E:\PyTorch_Build\pytorch> $env:LIB = "$env:CUDA_PATH\lib\x64;$env:LIB" PS E:\PyTorch_Build\pytorch> $env:INCLUDE = "$env:CUDA_PATH\include;$env:INCLUDE" PS E:\PyTorch_Build\pytorch> PS E:\PyTorch_Build\pytorch> # 验证 CUDA 安装 PS E:\PyTorch_Build\pytorch> Write-Host "🔍 验证 CUDA 安装:" 🔍 验证 CUDA 安装: PS E:\PyTorch_Build\pytorch> nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2025 NVIDIA Corporation Built on Wed_Jul_16_20:06:48_Pacific_Daylight_Time_2025 Cuda compilation tools, release 13.0, V13.0.48 Build cuda_13.0.r13.0/compiler.36260728_0 PS E:\PyTorch_Build\pytorch> # 安装 OpenBLAS 作为替代 PS E:\PyTorch_Build\pytorch> $openBlasUrl = "https://github.com/xianyi/OpenBLAS/releases/download/v0.3.27/OpenBLAS-0.3.27-x64.zip" PS E:\PyTorch_Build\pytorch> $openBlasPath = "E:\PyTorch_Build\OpenBLAS" PS E:\PyTorch_Build\pytorch> PS E:\PyTorch_Build\pytorch> # 下载并解压 OpenBLAS PS E:\PyTorch_Build\pytorch> Invoke-WebRequest -Uri $openBlasUrl -OutFile "$openBlasPath.zip" PS E:\PyTorch_Build\pytorch> Expand-Archive -Path "$openBlasPath.zip" -DestinationPath $openBlasPath GAC Version Location --- ------- -------- False v4.0.30319 C:\Program Files\PowerShell\7\WindowsBase.dll OperationStopped: PS E:\PyTorch_Build\pytorch> PS E:\PyTorch_Build\pytorch> # 设置 CMake 选项 PS E:\PyTorch_Build\pytorch> $cmakeOptions = @( >> "-S ." >> "-B build" >> "-GNinja" >> "-DCMAKE_BUILD_TYPE=Release" >> "-DUSE_CUDA=ON" >> "-DUSE_CUDNN=ON" >> "-DCUDA_TOOLKIT_ROOT_DIR=`"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0`"" >> "-DCUDNN_ROOT=`"E:/Program Files/NVIDIA/CUDNN/v9.12`"" >> "-DTORCH_CUDA_ARCH_LIST=`"8.6`"" >> "-DBUILD_PYTHON=ON" >> "-DBLAS=OpenBLAS" >> "-DOPENBLAS_HOME=`"$openBlasPath`"" >> "-DATEN_NO_TEST=ON" >> ) PS E:\PyTorch_Build\pytorch> PS E:\PyTorch_Build\pytorch> # 执行 CMake 配置 PS E:\PyTorch_Build\pytorch> cmake @cmakeOptions CMake Deprecation Warning at CMakeLists.txt:9 (cmake_policy): The OLD behavior for policy CMP0126 will be removed from a future version of CMake. The cmake-policies(7) manual explains that the OLD behaviors of all policies are deprecated and that a policy should be set to OLD only under specific short-term circumstances. Projects should be ported to the NEW behavior and not rely on setting a policy to OLD. CMake Warning at CMakeLists.txt:421 (message): TensorPipe cannot be used on Windows. Set it to OFF CMake Warning at CMakeLists.txt:423 (message): KleidiAI cannot be used on Windows. Set it to OFF CMake Warning at CMakeLists.txt:435 (message): Libuv is not installed in current conda env. Set USE_DISTRIBUTED to OFF. Please run command 'conda install -c conda-forge libuv=1.39' to install libuv. -- Current compiler supports avx2 extension. Will build perfkernels. -- Could not find hardware support for NEON on this machine. -- No OMAP3 processor on this machine. -- No OMAP4 processor on this machine. -- Compiler does not support SVE extension. Will not build perfkernels. CMake Warning at CMakeLists.txt:841 (message): x64 operating system is required for FBGEMM. Not compiling with FBGEMM. Turn this warning off by USE_FBGEMM=OFF. -- Could NOT find CUDA (missing: CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) (found version "13.0") CMake Warning at cmake/public/cuda.cmake:31 (message): PyTorch: CUDA cannot be found. Depending on whether you are building PyTorch or a PyTorch dependent library, the next warning / error will give you more info. Call Stack (most recent call first): cmake/Dependencies.cmake:44 (include) CMakeLists.txt:869 (include) CMake Warning at cmake/Dependencies.cmake:76 (message): Not compiling with CUDA. Suppress this warning with -DUSE_CUDA=OFF. Call Stack (most recent call first): CMakeLists.txt:869 (include) -- Building using own protobuf under third_party per request. -- Use custom protobuf build. CMake Warning at cmake/ProtoBuf.cmake:37 (message): Ancient protobuf forces CMake compatibility Call Stack (most recent call first): cmake/ProtoBuf.cmake:87 (custom_protobuf_find) cmake/Dependencies.cmake:107 (include) CMakeLists.txt:869 (include) CMake Deprecation Warning at third_party/protobuf/cmake/CMakeLists.txt:2 (cmake_minimum_required): Compatibility with CMake < 3.10 will be removed from a future version of CMake. Update the VERSION argument <min> value. Or, use the <min>...<max> syntax to tell CMake that the project requires at least <min> but has been updated to work with policies introduced by <max> or earlier. -- -- 3.13.0.0 -- Caffe2 protobuf include directory: $<BUILD_INTERFACE:E:/PyTorch_Build/pytorch/third_party/protobuf/src>$<INSTALL_INTERFACE:include> -- Trying to find preferred BLAS backend of choice: OpenBLAS -- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off -- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off CMake Error at cmake/Modules/FindOpenBLAS.cmake:58 (MESSAGE): Could not find OpenBLAS Call Stack (most recent call first): cmake/Dependencies.cmake:182 (find_package) CMakeLists.txt:869 (include) -- Configuring incomplete, errors occurred! PS E:\PyTorch_Build\pytorch>“
最新发布
09-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

10km

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值