Using thread support provided by c++0x on cygwin.

Discussion in 'C++' started by mangesh sawant, Feb 13, 2011.

  1. Hi,

    I am trying to compile following code using gcc version "g++ (GCC)
    4.3.4 20090804 (release) 1" on cygwin
    ------------------------------------------------------------------------------------------------------------
    #include <iostream>
    #include <thread>
    using namespace std;

    void hello()
    {
    cout << "Hello Concurrent World!" << endl;
    }

    int main()
    {
    cout << "starting" << endl;
    thread t(hello);
    t.join();
    cout << "ending" << endl;
    return 0;
    }
    ------------------------------------------------------------------------------------------

    When i try to compile this like :
    g++ -D_POSIX_TIMEOUTS -D_GLIBCXX__PTHREADS -D_GLIBCXX_HAS_GTHREADS -
    enable-auto-import -std=c++0x sample.cpp --lpthread

    I get folowing error :

    sample.cpp:2:18: error: thread: No such file or directory
    sample.cpp: In function `int main()':
    sample.cpp:13: error: `thread' was not declared in this scope
    sample.cpp:13: error: expected `;' before `t'
    sample.cpp:14: error: `t' was not declared in this scope

    Can anyone help with this?? Do I need to have a higher version of
    gcc??
    mangesh sawant, Feb 13, 2011
    #1
    1. Advertising

  2. On Feb 13, 9:07 am, mangesh sawant <> wrote:
    > Hi,
    >
    > I am trying to compile following code using gcc version "g++ (GCC)
    > 4.3.4 20090804 (release) 1"  on cygwin
    > ------------------------------------------------------------------------------------------------------------
    > #include <iostream>
    > #include <thread>
    > using namespace std;
    >
    > void hello()
    > {
    >  cout << "Hello Concurrent World!" << endl;
    >
    > }
    >
    > int main()
    > {
    >  cout << "starting" << endl;
    >  thread t(hello);
    >  t.join();
    >  cout << "ending" << endl;
    >  return 0;}
    >
    > ------------------------------------------------------------------------------------------
    >
    > When i try to compile this like :
    > g++ -D_POSIX_TIMEOUTS -D_GLIBCXX__PTHREADS -D_GLIBCXX_HAS_GTHREADS -
    > enable-auto-import -std=c++0x sample.cpp  --lpthread
    >
    > I get folowing error :
    >
    > sample.cpp:2:18: error: thread: No such file or directory
    > sample.cpp: In function `int main()':
    > sample.cpp:13: error: `thread' was not declared in this scope
    > sample.cpp:13: error: expected `;' before `t'
    > sample.cpp:14: error: `t' was not declared in this scope
    >
    > Can anyone help with this?? Do I need to have  a higher version of
    > gcc??


    Hi

    I compiled and ran you program under Suse Linux/g++ 4.5.0 with the
    following
    command:
    g++ -std=c++0x -pthread thread_test.c++ -o thread_test
    It's OK and I got output. Indeed the -pthread options is required.
    I compiled and ran the program with your command excluded
    enable-auto-import and -lpthread (not two dashes) and it is OK too.
    Based on the error messages you received, I think
    you don't have thread library and you have to install a newer one.
    Mine is good, but the newest version of GCC is 4.5.2.

    HTH
    -- Saeed Amrollahi
    Saeed Amrollahi, Feb 13, 2011
    #2
    1. Advertising

  3. mangesh sawant

    Andy Venikov Guest

    On 02/13/2011 01:07 AM, mangesh sawant wrote:
    > Hi,
    >
    > I am trying to compile following code using gcc version "g++ (GCC)
    > 4.3.4 20090804 (release) 1" on cygwin
    > ------------------------------------------------------------------------------------------------------------
    > #include<iostream>
    > #include<thread>
    > using namespace std;
    >
    > void hello()
    > {
    > cout<< "Hello Concurrent World!"<< endl;
    > }
    >
    > int main()
    > {
    > cout<< "starting"<< endl;
    > thread t(hello);
    > t.join();
    > cout<< "ending"<< endl;
    > return 0;
    > }
    > ------------------------------------------------------------------------------------------
    >
    > When i try to compile this like :
    > g++ -D_POSIX_TIMEOUTS -D_GLIBCXX__PTHREADS -D_GLIBCXX_HAS_GTHREADS -
    > enable-auto-import -std=c++0x sample.cpp --lpthread
    >
    > I get folowing error :
    >
    > sample.cpp:2:18: error: thread: No such file or directory
    > sample.cpp: In function `int main()':
    > sample.cpp:13: error: `thread' was not declared in this scope
    > sample.cpp:13: error: expected `;' before `t'
    > sample.cpp:14: error: `t' was not declared in this scope
    >
    > Can anyone help with this?? Do I need to have a higher version of
    > gcc??
    >
    >


    As far as I remember 4.3 did not have support for threads yet.
    Experimental support was added in 4.4 but not advertised.
    In 4.5 has official incomplete support for threads.

    HTH,
    Andy.
    Andy Venikov, Feb 13, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    425
  2. Replies:
    0
    Views:
    426
  3. WELCOME to

    , Sep 3, 2003, in forum: Python
    Replies:
    1
    Views:
    509
    Robin Becker
    Sep 5, 2003
  4. Replies:
    0
    Views:
    410
  5. Replies:
    33
    Views:
    3,992
    Ian Collins
    Apr 28, 2008
Loading...

Share This Page