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
相关产品推荐
相关产品推荐

