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

如何在GCC中设置模块搜索路径?已知Clang支持-fprebuilt-module-path选项

在GCC中设置预编译模块搜索路径的方法

GCC里对应Clang -fprebuilt-module-path 的功能,是通过 -fmodule-path 选项实现的,它专门用来指定预编译模块(.gcm 格式文件)的搜索目录。

基础使用示例

如果你的预编译模块都放在 ./prebuilt-modules 目录下,编译源码时可以这样指定路径:

g++ -fmodule-path=./prebuilt-modules -c main.cpp

要是有多个模块目录需要搜索,不同系统用不同分隔符:

  • Linux/macOS 用冒号分隔:
    g++ -fmodule-path=./local-modules:../third-party-modules -c main.cpp
    
  • Windows 用分号分隔:
    g++ -fmodule-path=.\local-modules;..\third-party-modules -c main.cpp
    

注意事项

  • GCC对C++模块的支持从GCC 11开始引入,建议使用GCC 12及以上版本,模块功能更稳定完善。
  • 当代码中使用 import 导入模块时,GCC会自动在 -fmodule-path 指定的目录下查找对应的预编译模块文件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 15:15:16