1

I am having trouble with the g++ compiler. On my work machine (running OS X 10.10.4) I was experimenting with some code using Xcode. The code did compile succesfully, and the resulting executable works as expected. Output of clang++ --version:

Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) Target: x86_64-apple-darwin14.4.0 Thread model: posix

Then I decided to compile this code on a server running Debian 8 with g++. The output of g++ --version:

g++ (Debian 4.9.2-22) 4.9.2 Copyright (C) 2014 Free Software Foundation, Inc.

The code won't even compile using g++. The command I tried using: g++ -std=c++11 -pthread main.cpp

I get the following error messages:

main.cpp: In function 'int main()':

main.cpp:32:106: error: invalid use of incomplete type 'class std::packaged_task' std::shared_ptr > ptr(new std::packaged_task(std::bind(factorial, 6)));

In file included from main.cpp:11:0:

/usr/include/c++/4.9/future:120:11: error: declaration of 'class std::packaged_task' class packaged_task; ^

main.cpp:33:22: error: variable 'std::future fu1' has initializer but incomplete type std::future fu1 = ptr->get_future(); ^

main.cpp:33:31: error: invalid use of incomplete type 'class std::packaged_task' std::future fu1 = ptr->get_future(); ^

In file included from main.cpp:11:0:

/usr/include/c++/4.9/future:120:11: error: declaration of 'class std::packaged_task' class packaged_task; ^

main.cpp: In lambda function:

main.cpp:34:48: error: invalid use of incomplete type 'class std::packaged_task' std::function task1 = &ptr{ ptr->operator()(); }; ^

In file included from main.cpp:11:0:

/usr/include/c++/4.9/future:120:11: error: declaration of 'class std::packaged_task' class packaged_task; ^

main.cpp: In function 'int main()':

main.cpp:36:38: error: variable 'std::packaged_task t' has initializer but incomplete type std::packaged_task t(std::bind(factorial, 5)); ^

main.cpp:37:22: error: variable 'std::future fu2' has initializer but incomplete type std::future fu2 = t.get_future(); ^

My code:

#include <iostream>
#include <thread>
#include <future>
#include <memory>

using std::cout;
using std::cin;
using std::endl;

unsigned long long int factorial(unsigned long long int num)
{
    unsigned long long int N = num;
    for (unsigned long long int i = num; i > 1; --i)
    {
        num *=(--N);
    }

    return num;
}

int main()
{

    std::shared_ptr<std::packaged_task<int()> > ptr(new std::packaged_task<int()>(std::bind(factorial, 6)));
    std::future<int> fu1 = ptr->get_future();
    std::function<void()> task1 = [&ptr](){ ptr->operator()(); };

    std::packaged_task<int()> t(std::bind(factorial, 5));
    std::future<int> fu2 = t.get_future();
    std::function<void()> task2 = [&t](){ t(); };

    std::thread threads[2];

    threads[0] = std::thread(task1);
    threads[1] = std::thread(task2);

    cout << fu1.get() << endl;
    cout << fu2.get() << endl;

    threads[0].join();
    threads[1].join();

    return 0;
}

What could be the issue with g++?

10
  • Or better <functional> ;) Commented Jul 2, 2015 at 12:42
  • I included <functional> and got the same error message Commented Jul 2, 2015 at 12:42
  • Oops, yes functional. But nvm if it doesn't help anyway. Commented Jul 2, 2015 at 12:43
  • GCC 5.1.0 will compile the code. Commented Jul 2, 2015 at 12:44
  • gcc version 4.9.2 (Debian 4.9.2-21) also compiles it Commented Jul 2, 2015 at 12:45

1 Answer 1

1

It seems, that std::future & std::async are not implemented on the armel architecture for some reason.

I can't really find out why is this (some argue on mailing lists, that they are not implemented by design, some others say this is a bug) and what is the current state of the problem.

However, I've also found a reply that stated this may be already resolved in the newer versions of libstdc++(My system is running the Testing version of debian, I do not have these versions yet, and I don't plan to get the package from unstable repos, so I'll just wait for it).

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, my arm-linux-gnueabi-g++ 4.9.2 also cannot compile the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.