Como compilar um programa c ++ 11 usando o futuro no Ubuntu 12.04? [fechadas]

1

Estou tentando compilar um programa c ++ no Ubuntu 12.04. Estou usando o g ++ 4.7 (instalado de um ppa). Estou usando o std :: future, mas tenho um erro.

O código:

$ cat main.cpp

#include <iostream>
#include <boost/thread/thread.hpp>
#include <future>

int foo(const int & i)
{
    return i*i;
}

int main()
{
    for(int i = 0; i<10; ++i)
    {
        std::future< int > Foo = boost::bind(&foo, i);
        std::cout<<Foo<<std::endl;
    }
    return 0;
}

Meu Makefile:

$ cat Makefile 
all:ex

CC= g++-4.7 -std=gnu++0x
link= -o
arg= -c -o
lib= -lboost_thread-mt

objets= main.o

ex: ${objets}
    @${CC} ${link} ex ${objets} ${lib}

%.o: %.cpp %.h
    @${CC} ${arg} $@ $< ${lib}

O erro:

$ make
g++    -c -o main.o main.cpp
In file included from /usr/include/c++/4.6/future:35:0,
                 from main.cpp:3:
/usr/include/c++/4.6/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
main.cpp: In function ‘int main()’:
main.cpp:14:3: error: ‘future’ is not a member of ‘std’
main.cpp:14:16: error: expected primary-expression before ‘int’
main.cpp:14:16: error: expected ‘;’ before ‘int’
main.cpp:17:14: error: ‘Foo’ was not declared in this scope
make: *** [main.o] Error 1

Como se livrar disso? :)

    
por user135505 25.02.2013 / 15:53

1 resposta

0

Por favor, altere o makefile como este

CC=g++
CFLAGS=-c -Wall -std=gnu++0x
LDFLAGS=
SOURCES=main.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=main

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
   $(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o:
   $(CC) $(CFLAGS) $< -o $@

Quando tentei compilar, estava jogando esse erro

main.cpp: In function ‘int main()’:
main.cpp:14:53: error: conversion from ‘boost::_bi::bind_t<int, int (*)(const int&), boost::_bi::list1<boost::_bi::value<int> > >’ to non-scalar type ‘std::future<int>’ requested
main.cpp:15:20: error: cannot bind ‘std::ostream {aka std::basic_ostream<char>}’ lvalue to ‘std::basic_ostream<char>&&’
In file included from /usr/include/c++/4.7/iostream:40:0,
                 from main.cpp:1:
/usr/include/c++/4.7/ostream:600:5: error:   initializing argument 1 of ‘std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = std::future<int>]’
make: *** [main.o] Error 1

Por que você não experimenta o programa de exemplo mostrado aqui? link

    
por thefourtheye 12.04.2013 / 15:04