0

I am building gcc 9.10 and it works great with c threads but im doing something wrong with g++ and libstdc++-v3 I just dont know what.

I compile gcc/g++, glibc, and libstdc++-v3 I see that the file at include/c++/9.1.0/threads When I go to compile a simple test program I get

error: ‘thread’ is not a member of ‘std’

C pthread test program compiles

#include <pthread.h>
int main(){
    tpthread_t t;
}

C test program compiles

#include <threads.h>
int main(){
    thrd_t t;
}

Cxx test program does not compile

#include <thread>
int main(){
    std::thread t;
}

Gets error

error: ‘thread’ is not a member of ‘std’

Looking into the header include/c++/9.1.0/threads

#if defined(_GLIBCXX_HAS_GTHREADS)

it looks like it skips everything if that is not defined how can I check to see if thats the case and then why?

I made this little test and it compiles indicating to me that _GLIBCXX_HAS_GTHREADS is not defined

int main(){
    #if defined(_GLIBCXX_HAS_GTHREADS)
    123 here error
    #endif
}

when compiling libstdc++-v3 I use

../libstdc++-v3/configure -v --enable-libstdcxx-threads=yes

even though I would think threads should be enabled by default on a linux x64 system

The other question doesnt help my situation it was from a long time ago and gcc has changed. One comment looks like it touches on my issue but doesnt go any deeper

If you look in the thread header, it appears that the class only exists #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1). I'm not sure though, what you'd have to do to have those defined

Thats the issue im having but theres no solution

jeff8j
  • 33
  • 5
  • Possible duplicate of [std::thread error (thread not member of std)](https://stackoverflow.com/questions/2519607/stdthread-error-thread-not-member-of-std) – BattleTested_закалённый в бою May 12 '19 at 23:38
  • I believe that may have been showing the same error but a different cause. Gcc has threads now by default, im not using -ansi, and not cross compiling. I can use the ubuntu version 7.4 and compile the cxx test so im thinking something wrong with my configuration – jeff8j May 12 '19 at 23:46
  • @jeff8j Can you please mention the command that you are running for compilation? – Kunal Puri May 13 '19 at 03:45
  • Adding --enable-threads=yes is what I was missing ../libstdc++-v3/configure -v --enable-threads=yes --disable-multilib make -j 8 make install The tests work now and compile as they should with g++ test.cxx – jeff8j May 14 '19 at 06:47

1 Answers1

0

The answer was to configure with --enable-threads=yes I dont know why that was so hard to find and why thats not default

jeff8j
  • 33
  • 5