0

I am unable to compile C++ thread library on my Ubuntu Linux system. With every option I give while compiling I always get this error

Either I compile giving

alc:~/practice/C++$ g++ -o thr thr.cpp -lpthread -std=c++11

or

alc:~/practice/C++$ g++ -o thr thr.cpp -std=c++0x -lpthread
In file included from thr.cpp:3:0:
/usr/include/c++/4.9/thread: In constructor ‘std::thread::thread(_Callable&&, _Args&& ...)’:
/usr/include/c++/4.9/thread:138:46: error: ‘__bind_simple’ is not a member of ‘std’
         _M_start_thread(_M_make_routine(std::__bind_simple(
                                              ^~~~~~~~~~~~~
/usr/include/c++/4.9/thread:138:46: note: suggested alternative: ‘__big_div_impl’
         _M_start_thread(_M_make_routine(std::__bind_simple(
                                              ^~~~~~~~~~~~~
                                              __big_div_impl

This is my C++ program

#include <c++/4.9/iostream>
#include <c++/4.9/thread>

using namespace std;

void func_dummy(int N)
{
    for(int i=0 ; i < N ; i++)
        cout << "Thread 1 : function pointer" << endl;
}


int main()
{
    thread thr1(func_dummy, 2);

    thr1.join();

    return 0;
}
1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
  • 2
    `#include ` -- That's odd that you need to specify a path like this for the standard header. Maybe you should fix your compiler installation so that you don't need to be do this. – PaulMcKenzie Jul 08 '20 at 21:49
  • And see [**Why is “using namespace std;” considered bad practice?**](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – Andrew Henle Jul 08 '20 at 21:51
  • Following on from @PaulMcKenzie's comment, it is possible that the headers under the "4.9" folder include other system files, which will be included from the standard include path. Since those are likely different library versions, you run into problems mixing the headers from the two. – 1201ProgramAlarm Jul 08 '20 at 21:54
  • you shouuld use #include #include – Paul Baxter Jul 08 '20 at 21:59
  • Thanks a lot for the suggestions. The path for the header files were incorrect. I changed the path and it worked. – Abdul Latif Curtay Jul 12 '20 at 02:41

0 Answers0