MAC 安装boost
时间: 2023-09-14 13:12:21 浏览: 156
要在MAC上安装Boost,可以按照以下步骤进行操作:
1. 首先,打开终端并使用以下命令安装boost和cmake:
```
brew install boost
brew install cmake
```
2. 安装完成后,可以使用以下命令检查Boost的版本:
```
#include <iostream>
#include <boost/version.hpp>
int main(int argc, char const *argv[]) {
std::cout << BOOST_VERSION << std::endl;
return 0;
}
```
编译并运行以上代码:
```
clang main.cpp -o main
./main
```
3. 接下来,创建一个项目并修改CMakeLists.txt文件:
```
cmake_minimum_required(VERSION 3.0.0)
project(demo VERSION 0.1.0)
set(BOOST_ROOT "/usr/local/Cellar/boost/1.75.0_1")
find_package(Boost 1.75.0 COMPONENTS system)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(demo main.cpp)
target_link_libraries(demo ${Boost_LIBRARIES})
endif(Boost_FOUND)
```
4. 在终端中进入项目的build文件夹,并执行以下命令进行编译:
```
cmake .. && make
```
这样就可以在MAC上成功安装和配置Boost库了。请确保按照以上步骤操作,并根据您的具体需求进行相应的修改。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [macOS 中Boost的安装和使用](https://blog.csdn.net/Mrknowledge/article/details/80323743)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [boost-note-mac.dmg](https://download.csdn.net/download/libbybyron/17410259)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [mac安装和使用boost库](https://blog.csdn.net/Lazybones_3/article/details/114214652)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文