【问题标题】:Make Sublime Text use gcc4.8 on Mac让 Sublime Text 在 Mac 上使用 gcc4.8
【发布时间】:2013-10-14 15:00:21
【问题描述】:

我想将 Sublime Text(2/ 3alpha) 用于简单的 c++ 程序,但我不能使用 c++11。我尝试更改构建文件,但添加 -std=c++11 没有帮助。我确实安装了带有 macports 的 GCC4.8(并且它可以正常工作)但显然崇高的文本正在使用 4.2 变体。如何让它使用较新的?我尝试在谷歌上搜索解决方案,但到目前为止还没有找到。感谢您的耐心等待!

【问题讨论】:

  • 能否请您发布 SublimeBuild 文件的内容和您使用终端调用 gcc4.8 的命令行?
  • 我知道这不是你想听到的,但如果你在 mac 上只使用 clang,命令行工具版本比 gcc 版本更新得多
  • { "cmd": ["g++ -Wall -Wextra -pedantic -std=c++11 ${file} -o ${file_path}/${file_base_name}"], "shell": true, "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "${file_path}", "selector": "source.c, source.c++", }
  • @Praetorian 这是 SublimeBuild 文件。希望它足够好。
  • @aaronman 我很高兴使用clang,但我现在不知道如何使用最新版本。用 clang++ 替换 g++ 会产生相同的结果。

标签: c++ macos c++11 sublimetext2 macports


【解决方案1】:

我认为您需要指定 GCC 4.8 可执行文件的绝对路径(因为 g++ 可能只是系统上 GCC 4.2 的符号链接)。

这是我在 Ubuntu 上的 gcc-4.8.1 (Release).sublime-build

{
    "cmd": ["/opt/gcc-4.8.1/bin/g++", "${file}", "-o", "${file_path}/${file_base_name}", "-std=c++11", "-Wall", "-O3"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++, source.cxx",

    "variants":
    [
        {
            "name": "Run",
            "cmd": ["bash", "-c", "${file_path}/${file_base_name}"]
        }
    ]
}

请注意,我在 'cmd' 中传递了一个绝对路径。

【讨论】:

    【解决方案2】:

    正如 Tom Knapen 所建议的,解决方案是包含新 gcc 的完整路径。在我的情况下,使用 macports gcc,这是:

    /opt/local/bin/g++-mp-4.8
    

    所以 sublime-build 看起来像这样:

    {
        "cmd": ["/opt/local/bin/g++-mp-4.8", "${file}", "-o", "${file_path}/${file_base_name}", "-std=c++11", "-Wall", "-O2"],
        "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
        "working_dir": "${file_path}",
        "selector": "source.c, source.c++,
    }
    

    【讨论】:

      猜你喜欢
      • 2013-04-27
      • 1970-01-01
      • 2013-07-21
      • 2014-08-10
      • 2014-03-07
      • 2016-04-12
      • 1970-01-01
      • 2012-12-11
      • 2014-04-22
      相关资源
      最近更新 更多