Build C ++ 11 with TextMate?

advertisements

With a regular C++98 program, to run it from TextMate, all I need to do is a ⌘R to run it from TextMate. With C++11, however that does not work out of the box. For instance if I have the following program:

#include <iostream>
using namespace std;

int main()
{
    for (auto i : {1, 2, 3})
        cout << i << " ";

    cout << "\n";
}

Then doing a ⌘R results in the following C++11 build errors:

untitled:6:10: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    for (auto i : {1, 2, 3})
         ^
untitled:6:17: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
    for (auto i : {1, 2, 3})
                ^
untitled:6:19: error: cannot deduce type of initializer list because std::initializer_list was not found; include <initializer_list>
    for (auto i : {1, 2, 3})
                  ^
2 warnings and 1 error generated.

This program runs fine in Xcode or with a simple make (I have a export CXXFLAGS="-std=c++0x” in my .bashrc which takes care of make). I can also build it from the command-line with a clang++ -std=c++11 test.cpp, so this is not a compiler issue, but something to do with my TextMate configuration.

Looking at the TextMate Run bundle, I can see that it references TM_CXX_FLAGS. From TextMate Preferences, I appended -std=c++0x and -Wc++11-extensions to TM_CXX_FLAGS. That did not seem to help.

Clearly I’m overlooking something obvious here.

Any pointers on how I could fix this?


The default variables in Preferences → Variables are disabled by default.

So you need to enable TM_CXX_FLAGS by checking the check box in the left-most column.