5

I build gcc 4.8.1 and libstdc++.so.6.0.18, soft link libstdc++.so.6.0.18 to libstdc++.so.6 And I checked g++ -v, it is 4.8.1

test.cpp:11:9: error: ‘thread’ is not a member of ‘std’
     std::thread t(hello);

But even a single line cound not be compiled..

How to fix it?

total code:

#include <iostream>
#include <thread>

void hello()
{
        std::cout<<"Hello Concurrent World\n";
}

int main(int argc, char * argv[])
{
        std::thread t(hello);
        t.join();

        return 0;
}

g++ -H -std=c++11 test.cpp -o test info:

/usr/include/asm/errno.h
/usr/include/bits/byteswap.h
/usr/include/bits/endian.h
/usr/include/bits/errno.h
/usr/include/bits/locale.h
/usr/include/bits/sched.h
/usr/include/bits/select.h
/usr/include/bits/sigset.h
/usr/include/bits/stdio_lim.h
/usr/include/bits/sys_errlist.h
/usr/include/bits/typesizes.h
/usr/include/bits/waitflags.h
/usr/include/bits/waitstatus.h
/usr/include/errno.h
/usr/include/gnu/stubs-64.h
/usr/include/gnu/stubs.h
/usr/local/include/c++/4.8.1/bits/ctype_base.h
/usr/local/include/c++/4.8.1/bits/ctype_inline.h
/usr/local/include/c++/4.8.1/cerrno
/usr/local/include/c++/4.8.1/clocale
/usr/local/include/c++/4.8.1/cstdio
/usr/local/include/c++/4.8.1/cstdlib
/usr/local/include/c++/4.8.1/ctime
/usr/local/include/c++/4.8.1/cwctype
Bing Hsu
  • 692
  • 1
  • 8
  • 14
  • 1
    Did you `#include `? – zneak Sep 25 '13 at 00:34
  • Definitely. And I also use std=c++11. Same problem with clang++ test.cpp:11:14: error: no member named 'thread' in namespace 'std'; did you mean 'fread'? std::thread t(hello); ~~~~~^~~~~~ fread – Bing Hsu Sep 25 '13 at 00:34
  • [Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See http://SSCCE.org for guidance.](http://stackoverflow.com/help/on-topic) – n. m. could be an AI Sep 25 '13 at 00:34
  • If `#include ` produces no error but `std::thread` isn't usable, you've got a very strange problem. The snippet compiles (but doesn't run for security reasons) on ideone and on my machine. – zneak Sep 25 '13 at 00:38
  • Use `-H` compiler switch to see what files are included, with their absolute paths. – n. m. could be an AI Sep 25 '13 at 00:38
  • @n.m. updated.. seems not wrong – Bing Hsu Sep 25 '13 at 00:41
  • You need to add `-H` to your existing compilation command, not use it on its own. Like `g++ -std=c++11 -c test.cpp -H`. – n. m. could be an AI Sep 25 '13 at 00:41
  • I use g++ -H -std=c++11 test.cpp -o test – Bing Hsu Sep 25 '13 at 00:43
  • If the very first file you are including is ``, then the very first line of the output should be a single dot followed by the full path to `iostream`, like this: `. /usr/lib/gcc/i686-pc-linux-gnu/4.8.1/include/g++-v4/iostream `. If you are getting something else, your gcc installation is weirdly broken. – n. m. could be an AI Sep 25 '13 at 00:47
  • Use `g++ -v` when compiling. It should say "#include <...> search starts here:" with a list of directories, followed by "End of search list." Please try `g++ -v -std=c++11 test.cpp -o test 2>&1 | awk 'BEGIN{i=0} /^#include/{i=1} /^End/{i=0;print;} {if(i)print}'` and post the output. Also, how did you configure the compiler? `g++ -v` by itself will give you that info. –  Sep 25 '13 at 02:10
  • @ChronoKitsune #include "..." search starts here: #include <...> search starts here: /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1 /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/x86_64-unknown-linux-gnu /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/backward /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include /usr/local/include /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include-fixed /usr/include – Bing Hsu Sep 25 '13 at 02:15
  • The only thing I might guess is that it is using a single threaded model or whatever parameters you specified to configure or CFLAGS perhaps resulted in broken behavior. How exactly did you configure and make GCC? `g++ -v` will give you the configuration if you forgot, and did you use `make CFLAGS=...` or `make -j 2 bootstrap` or just `make bootstrap` (I did this one) or just `make`? Also, please report the `Thread model` output of `g++ -v`. It should say "posix". –  Sep 25 '13 at 07:41
  • 1
    http://stackoverflow.com/questions/2519607/stdthread-error-thread-not-member-of-std – evergreen Aug 25 '14 at 14:41
  • > checked http://stackoverflow.com/questions/2519607/stdthread-error-thread-not-member-of-std – evergreen Aug 25 '14 at 14:43

0 Answers0