C ++ 11 с gcc 4.6.1 на Mac

Я новичок в Mac и пытаюсь заставить работать gcc 4.6.

Я установил MacPorts и установил gcc 4.6.1 (выполнив sudo port install gcc46 ). Я пытаюсь скомпилировать простой тестовый код, который отлично компилируется в Linux (с gcc 4.6.1 и 4.6.2) и Windows, но получаю ошибки, из-за которых мне кажется, что с установленными библиотеками что-то не так.

#include <iostream>
#include <type_traits>
#include <future>

struct test {
    void get() {}
};

/*template<typename Func>
test async(const Func &f) {
    f();
    return test();
}*/

using namespace std;

int main (int argc, const char * argv[])
{
    auto t1 = async([]() -> int{
        cout << "This is thread 1" << endl;
        return 1;
    });

    auto t2 = async([]() -> int {
        cout << "This is thread 2" << endl;
        return 2;
    });

    std::cout << "This is the main thread" << endl;

    t1.get();
    t2.get();

    return 0;
}

Сообщения об ошибках:

macbook01:Test fozi$ g++ main.cpp -o test -std=c++0x
main.cpp: In function 'int main(int, const char**)':
main.cpp:30:6: error: invalid use of incomplete type 'std::enable_if<true, std::future<int> >::type'
/opt/local/include/gcc46/c++/future:111:11: error: declaration of 'std::enable_if<true, std::future<int> >::type'
main.cpp:30:6: error: unable to deduce 'auto' from '<expression error>'
main.cpp:35:6: error: invalid use of incomplete type 'std::enable_if<true, std::future<int> >::type'
/opt/local/include/gcc46/c++/future:111:11: error: declaration of 'std::enable_if<true, std::future<int> >::type'
main.cpp:35:6: error: unable to deduce 'auto' from '<expression error>'
/opt/local/include/gcc46/c++/future: At global scope:
/opt/local/include/gcc46/c++/future:150:5: error: 'typename std::enable_if<(! std::is_same<typename std::decay<_Functor>::type, std::launch>::value), std::future<decltype (declval<_Fn>()((declval<_Args>)()...))> >::type std::async(_Fn&&, _Args&& ...) [with _Fn = main(int, const char**)::<lambda()>, _Args = {}, typename std::enable_if<(! std::is_same<typename std::decay<_Functor>::type, std::launch>::value), std::future<decltype (declval<_Fn>()((declval<_Args>)()...))> >::type = std::future<int>]', declared using local type 'main(int, const char**)::<lambda()>', is used but never defined [-fpermissive]
/opt/local/include/gcc46/c++/future:150:5: error: 'typename std::enable_if<(! std::is_same<typename std::decay<_Functor>::type, std::launch>::value), std::future<decltype (declval<_Fn>()((declval<_Args>)()...))> >::type std::async(_Fn&&, _Args&& ...) [with _Fn = main(int, const char**)::<lambda()>, _Args = {}, typename std::enable_if<(! std::is_same<typename std::decay<_Functor>::type, std::launch>::value), std::future<decltype (declval<_Fn>()((declval<_Args>)()...))> >::type = std::future<int>]', declared using local type 'main(int, const char**)::<lambda()>', is used but never defined [-fpermissive]

Обратите внимание, что если я использую свою фиктивную функцию async, она компилируется и работает нормально.

Я как бы застрял, мне нужно установить определенную библиотеку (версию)? Как мне это сделать?

6
задан Xeo 19 December 2011 в 01:54
поделиться