vladb
vladb

Reputation: 247

Make Sublime Text use gcc4.8 on Mac

I want to use Sublime Text(2/ 3alpha) for simple c++ programs, but I cannot use c++11. I tried changing the build file, but adding -std=c++11 does not help. I do have GCC4.8 installed with macports(and it works otherwise) but apparently sublime text is using the 4.2 variant. How do I make it use the newer one? I tried googling for a solution but haven't found one so far. Thank you for your patience!

Upvotes: 1

Views: 1283

Answers (2)

vladb
vladb

Reputation: 247

As Tom Knapen suggested, the solution is to include the full path of the newer gcc. In my case, with the macports gcc, this was:

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

So the sublime-build looks like this:

{
    "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++,
}

Upvotes: 0

Tom Knapen
Tom Knapen

Reputation: 2277

I think you need to specify the absolute path to your GCC 4.8 executable (since g++ is probably just a symlink to GCC 4.2 on your system).

Here's my gcc-4.8.1 (Release).sublime-build on Ubuntu:

{
    "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}"]
        }
    ]
}

Note that I'm passing an absolute path in 'cmd'.

Upvotes: 3

Related Questions