1、下载
去cmake官网下载对应版本的binaries or source code archives。
我电脑:Apple M1 Pro
、macOS:版本13.0.1 (22A400)
,下载的cmake-3.26.0-rc2-macos-universal.dmg
版本
2、安装
点击dmg拖拽安装后实验失败
cmake ..
zsh: command not found: cmake
于是在电脑Launchpad(启动台)
找到CMake
图标,点击启动
点击Tools
,选择How to Install For Command Line Use
给了三种安装方式:
文字版本:
One may add CMake to the PATH:
PATH="/Applications/CMake.app/Contents/bin":"$PATH"
Or, to install symlinks to '/usr/local/bin', run:
sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install
Or, to install symlinks to another directory, run:
sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install=/path/to/bin
于是在终端执行了
sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install
完成安装
3、验证
命令行验证版本号:
~ % cmake --version
cmake version 3.26.0-rc2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
写一个helloworld.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!";
return 0;
}
CMakeList.txt
文章来源:https://www.toymoban.com/news/detail-589602.html
cmake_minimum_required(VERSION 3.0)
project(HelloWord)
add_executable(hello_world helloword.cpp)
终端运行:文章来源地址https://www.toymoban.com/news/detail-589602.html
% mkdir build && cd build
build % cmake .. && make -j8
build % ./hello_world
Hello, World!%
到了这里,关于Mac安装cmake实践的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!