当前位置: 首页 > news >正文

Mac OS 15.5下使用gcc15.2的Modules模块功能出现无法链接的解决方法

在Mac OS 15.5系统中,最近想用C++23,试了试gcc15.2,发现出现无法链接模块功能:

首先下一个最简单的Helloworld.cpp:

import std;

int main()
{
std::println("Hello,world!");
return 0;
}

使用gcc15.2编译:

g++-15 -std=c++23 -fmodules helloworld.cpp

出现链接不到模块的错误:

Undefined symbols for architecture arm64:
"initializer for module std", referenced from:
__static_initialization_and_destruction_0() in ccEgD1TM.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status

参考了网上一位大神的文章介绍:https://download.csdn.net/blog/column/11938572/149222276

使用这个命令重新编译:g++ -std=c++23 -fmodules -fsearch-include-path bits/std.cc helloworld.cpp

bit/std.cc是std模块所在位置,我们需要找出gcc15.2在Mac OS中安装位置,使用这个命令可以找到:/* by yours.tools - online tools website : yours.tools/zh/post.html */ g++-15 -print-search-dirs

gcc15.2安装位置:

install: /opt/homebrew/Cellar/gcc/15.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin24/15/

programs: =/opt/homebrew/Cellar/gcc/15.2.0/bin/../libexec/gcc/aarch64-apple-darwin24/15/:/opt/homebrew/Cellar/gcc/15.2.0/bin/../libexec/gcc/:/opt/homebrew/Cellar/gcc/15.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin24/15/../../../../../../aarch64-apple-darwin24/bin/aarch64-apple-darwin24/15/:/opt/homebrew/Cellar/gcc/15.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin24/15/../../../../../../aarch64-apple-darwin24/bin/

libraries: =/opt/homebrew/Cellar/gcc/15.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin24/15/:/opt/homebrew/Cellar/gcc/15.2.0/bin/../lib/gcc/current/gcc/:/opt/homebrew/Cellar/gcc/15.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin24/15/../../../../../../aarch64-apple-darwin24/lib/aarch64-apple-darwin24/15/:/opt/homebrew/Cellar/gcc/15.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin24/15/../../../../../../aarch64-apple-darwin24/lib/:/opt/homebrew/Cellar/gcc/15.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin24/15/../../../aarch64-apple-darwin24/15/:/opt/homebrew/Cellar/gcc/15.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin24/15/../../../

可以看到std.cc模块位置是:/opt/homebrew/Cellar/gcc/15.2.0/include/c++/15/bits/std.cc

然后替换一下刚才的编译命令中std.cc的位置即可:

g++-15 -std=c++23 -fmodules -fsearch-include-path /opt/homebrew/Cellar/gcc/15.2.0/include/c++/15/bits/std.cc helloworld.cpp

./a.out
Hello,world!

大功告成,希望C++23成熟以后,不用自己手动指定模块位置吧。

http://www.jsqmd.com/news/225269/

相关文章:

  • AI智能实体侦测服务助力知识图谱构建:实体抽取自动化实践
  • RaNER模型技术深度:实体识别中的边界问题
  • RaNER模型部署详解:中文实体识别服务的高效实现
  • 9款免费AI论文工具揭秘:效率飙升300%,告别熬夜搞定毕业论文
  • 导师推荐9个AI论文软件,专科生轻松搞定毕业论文!
  • Qwen2.5-7B学术研究:学生党专属GPU方案,1小时1块钱
  • AI智能实体侦测服务如何应对错别字?鲁棒性增强策略分享
  • 混元翻译1.5实战:技术文档精准翻译
  • 企业级信息抽取系统搭建:AI智能实体侦测服务生产环境部署教程
  • 中文长文本识别优化:AI智能实体侦测服务分段推理实战技巧
  • 导师严选10个AI论文工具,专科生轻松搞定论文写作!
  • AI智能实体侦测服务支持多段落输入吗?长文档结构解析能力
  • 增加0.1nF电筒改进测量效果
  • HY-MT1.5-7B上下文理解:对话场景翻译优化技巧
  • 中文NER服务部署教程:RaNER模型快速上手指南
  • Qwen3-VL模型压缩教程:让视觉AI跑在低成本GPU上
  • 中文NER模型可解释性:RaNER决策过程分析
  • 中文命名实体识别难?AI智能实体侦测服务保姆级教程来助力
  • AI智能实体侦测服务响应式WebUI设计:动态标签技术实现解析
  • 智能实体识别服务:RaNER模型Docker部署教程
  • Qwen2.5-7B极速体验:比下载电影还简单的AI编程
  • AI智能实体侦测服务K8s部署:Helm Chart编写与集群管理
  • AI智能实体侦测服务一文详解:核心技术架构与应用场景剖析
  • 视觉大模型入门必看:Qwen3-VL云端体验已成主流
  • HY-MT1.5-1.8B部署实战:嵌入式设备移植指南
  • 开发者入门必看:AI智能实体侦测服务REST API调用指南
  • 如何提升召回率?AI智能实体侦测服务后处理策略实战
  • AI智能实体侦测服务配置中心:Apollo统一管理多环境参数
  • RaNER模型对抗样本:安全防护与鲁棒性提升
  • d3d10.dll文件丢失找不到 彻底修复解决办法分享