Gcc 4.5.1 configure options to support C ++ 0x streams

I am trying to compile gcc 4.5.1 for cygwin with thread support C ++ 0x. However, as a result, gcc does not recognize the -pthread option.

My configure command:

./configure --enable-bootstrap --enable-shared --enable-shared-libgcc
            --with-gnu-ld --enable-languages=c,c++ --enable-libgomp
            --enable-libssp --enable-threads=posix --with-__thread

Program Example:

#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;
}

I am compiling a program in C ++ using

$ gcc -Wall -g -std=c++0x -pthread Trial.cpp
gcc: unrecognized option '-pthread'
Trial.cpp: In function `int main()':
Trial.cpp:21:5: error: `thread' was not declared in this scope
Trial.cpp:21:12: error: expected `;' before `t'
Trial.cpp:22:5: error: `t' was not declared in this scope

My question is: how do I configure gcc?

+3
source share
2 answers

As you see in the error message, the problem is not with your configuration, but with your g ++ variant. Use

g++ -lpthread

for pthreads (POSIX threads) and

g++ -lboost_thread

to increase flows. (-pthread is wrong.)

see g ++ manual

man gcc
0
source

g++ -pthread -std=c++0x gcc -lstdc++.

, , ( ), , , ( () GCC ).

gcc -lstdc++ -std=c++0x -pthread your.cpp
g++ -std=c++0x -pthread your.cpp
0

Source: https://habr.com/ru/post/1761239/


All Articles