cmake version和sudo cmake version不一样
时间: 2023-08-26 12:05:02 浏览: 401
这是因为在终端中运行的`cmake`与在`sudo`下运行的`cmake`可能不是同一个版本。可能是因为你安装了多个版本的`cmake`,而`sudo`运行的是系统默认的版本,而不是你安装的版本。
你可以尝试在终端中输入以下命令,查看`cmake`的安装路径:
```
which cmake
```
然后在`sudo`下运行`cmake`时,指定你想要运行的`cmake`路径:
```
sudo /path/to/cmake version
```
或者将`cmake`的路径添加到`sudo`的环境变量中:
```
sudo env "PATH=$PATH:/path/to/cmake" cmake version
```
相关问题
sudo snap install cmake
您可以使用以下命令来通过snap安装cmake:
sudo snap install cmake --classic
这将安装cmake的最新版本。您可以使用以下命令来验证安装的版本:
cmake --version
请注意,使用snap安装的cmake版本可能不是最新的。如果您需要最新版本的cmake,您可以考虑其他安装方法,如源码安装或使用apt安装。
#### 引用[.reference_title]
- *1* *3* [CMake 安装、卸载(Ubuntu 18.04 LTS)](https://blog.csdn.net/i6101206007/article/details/113113633)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [2021-08-17](https://blog.csdn.net/weixin_42330983/article/details/119749534)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
(base) lmj@lmj-Ubuntu:/opt/sdk.20230309/horus_sdk_release/build$ sudo cmake ../ -- cmake version 3.22.1 CMake Deprecation Warning at CMakeLists.txt:4 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. -- The C compiler identification is unknown -- The CXX compiler identification is unknown CMake Error at CMakeLists.txt:11 (project): The CMAKE_C_COMPILER: arm-linux-gnueabihf-gcc is not a full path and was not found in the PATH. Tell CMake where to find the compiler by setting either the environment variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH. CMake Error at CMakeLists.txt:11 (project): The CMAKE_CXX_COMPILER: arm-linux-gnueabihf-g++ is not a full path and was not found in the PATH. Tell CMake where to find the compiler by setting either the environment variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH. -- Configuring incomplete, errors occurred! See also "/opt/sdk.20230309/horus_sdk_release/build/CMakeFiles/CMakeOutput.log". See also "/opt/sdk.20230309/horus_sdk_release/build/CMakeFiles/CMakeError.log".
根据你提供的错误信息,看起来 CMake 在配置项目时无法找到 C 和 C++ 编译器。这可能是由于缺少路径或编译器未正确安装所致。你可以尝试以下解决方法:
1. 确保你已经正确安装了 `arm-linux-gnueabihf-gcc` 和 `arm-linux-gnueabihf-g++` 编译器。你可以通过在终端中运行 `arm-linux-gnueabihf-gcc --version` 和 `arm-linux-gnueabihf-g++ --version` 来检查它们是否已安装。
2. 如果编译器已正确安装,但仍然无法找到,请尝试使用绝对路径设置环境变量 `CC` 和 `CXX`。例如,如果编译器的完整路径为 `/path/to/arm-linux-gnueabihf-gcc` 和 `/path/to/arm-linux-gnueabihf-g++`,你可以在终端中运行以下命令:
```
export CC=/path/to/arm-linux-gnueabihf-gcc
export CXX=/path/to/arm-linux-gnueabihf-g++
```
然后再次运行 `sudo cmake ../`。
3. 如果以上方法仍然无效,你可以尝试编辑 CMakeLists.txt 文件,在文件开头添加以下内容,指定编译器的完整路径:
```
set(CMAKE_C_COMPILER "/path/to/arm-linux-gnueabihf-gcc")
set(CMAKE_CXX_COMPILER "/path/to/arm-linux-gnueabihf-g++")
```
然后保存文件并再次运行 `sudo cmake ../`。
希望这些方法能够解决你的问题。如果你有任何其他疑问,请随时提问。
阅读全文