You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

M1 Mac使用boost::filesystem时arm64符号未定义问题解决方法

Boost Filesystem编译链接错误(arm64架构)

我在C++11中处理文件路径时,采用主流方案使用Boost库。通过brew安装了版本为1.81.0_1的Boost,编写的代码如下:

#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
    
int main(int argc, char* argv[]){
   if (argc < 2){
     std::cout << "Usage: tut1 path\n";
     return 1;
   }
   std::cout << argv[1] << " " << file_size(argv[1]) << '\n';
   return 0;
}

同时在~/.zshrc中添加了以下环境变量配置:

export CPATH=/opt/homebrew/include
export LIBRARY_PATH=/opt/homebrew/lib

执行编译命令:

clang main.cpp

之后出现链接错误:

Undefined symbols for architecture arm64:
"boost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)"
...
ld: symbol(s) not found for architecture arm64

已尝试添加-l参数,但问题仍未解决。


内容的提问来源于stack exchange,提问作者fold4wrap5

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 19:09:27