GAMES101:MacOS作业环境搭建

一、配置开发环境

1.1 安装编译软件

1.1.1 安装gcc/clang

  • x86:安装gcc
  • arm64:安装clang

查看gcc/clang的位置

where gcc
where clang

产看gcc/clang的版本

gcc --version
clang --version

 1.1.2 安装cmake

brew install cmake

1.2 安装开发库

1.2.1 安装Eigen

brew install eigen

二、安装编辑器VSCode

2.1 安装VSCode

2.2 必要插件

  • C/C++
  • CMake
  • CMake Tools

三、导入作业

3.1 编译源文件

  • 打开项目文件夹下的CMakeLists.txt文件
  • 修改CMakeLists.txt文件为如下内容
    cmake_minimum_required (VERSION 2.8.11)
    project (pa0)
    
    find_package(Eigen3 REQUIRED)
    include_directories("/opt/homebrew/Cellar/eigen/3.4.0_1/include")
    
    add_executable (pa0 main.cpp)

    【重点注意】

    • project (pa0) 修改为当前自己创建的项目名称(此处使用了项目文件的默认名pa0)

    • include_directories("/opt/homebrew/Cellar/eigen/3.4.0_1/include") 此路径为我们用到的库的路径,这里是我们引用到的eigen库的所在路径。

      • 终端键入查找eigen库的安装路径

        brew info eigen
    • add_executable (pa0 main.cpp) 使用main.cpp文件创建可执行文件pa0
  •  根据pdf的编译指导,在终端键入一下命令完成编译
    cd pa0 // 进入项目文件夹
    mkdir build
    cd build
    cmake ..
    make
  • 若上一步无编译错误,则运行可执行文件验证结果 。终端键入./pa0运行程序(这里的pa0是根据CMakeLists.txt中add_executable命令生成的可执行文件名)

3.2 解决编译错误

3.2.1 头文件引入错误

  • eigen库引入错误
    • 设置c_cpp_properties.json文件,在includePath属性中包含eigen库的路径
      {
          "configurations": [
              {
                  "name": "Mac",
                  "includePath": [
                      "${workspaceFolder}/**",
                      "/opt/homebrew/Cellar/eigen/3.4.0_1/include" // eigen库的路径
                  ],
                  "defines": [],
                  "macFrameworkPath": [
                      "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
                  ],
                  "compilerPath": "/usr/bin/clang",
                  "cStandard": "c17",
                  "cppStandard": "c++17",
                  "intelliSenseMode": "macos-clang-arm64"
              }
          ],
          "version": 4
      }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值