C++11, GCC 4.8.1,Code::Blocks, threading, what a head ache

11,378

probably to late for an answere, but here is what worked for me:

1. Get x86_64-w64-mingw32-gcc-4.8-stdthread-win64_rubenvb.7z from:

http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/rubenvb/gcc-4.8-experimental-stdthread/

2. Setup a new compiler in codeblocks with

  • x86_64-w64-mingw32-gcc-4.8.1.exe
  • x86_64-w64-mingw32-g++.exe
  • x86_64-w64-mingw32-g++.exe
  • ar.exe
  • windres.exe
  • mingw32-make.exe

3. Set the new compiler for your project

  • Right click in your project -> build options
  • Select the new compiler
  • Under compiler falgs check -std=c++0x and -std=c++11
  • Under Other options set -std=gnu++11

4. Have fun with c++11 concurrency

Hope that works for you also, as an alternative you can just use visual studio.

Share:
11,378

Related videos on Youtube

allegory
Author by

allegory

I love writing and writing code. Language experience: asm, C, C++, C#, Java, JS, lua, XML/HTML and VHDL. IT experience: Cisco(switches, routers), Netgear(switches, routers, wifi), Luxul/Pakedge(switches, routers, wifi). Other: Node, phonegap, apache cordova, Control4, URC(Complete Control and Total Control).

Updated on June 28, 2022

Comments

  • allegory
    allegory almost 2 years

    --EDIT If you would like to use MinGW GCC 8.4.1 and threads/mutex/futures/atomics do not download the Win32 threader version insted download the Posix version. --EDIT

    My installation of MinGW is as follows: x32-4.8.1-release-win32 (as the threader) - sjlj rev 5

    I have unpacked and correctly confirmed that MinGW GCC 4.8.1 (revision 5) is installed in C:\MinGW\mingw32. I have set up Code Blocks to look for the latest and greatest compiler in the correct path (this I am sure of). I can compile a normal program using #include iostream. Ok now when I try and run a program using #include thread it gives me "error: 'thread' is not a member of 'std'".

    Now here is what I have done and what I have tried:

    I am following a sort of template or tutorial here at cplusplus.com.
    I have the code exactly as it is presented on the webpage (towards the bottom).
    I have tried, in Code Blocks, to use Compiler flags "Have g++ follow the C++11 ISO language standard -std=c++11".

    I have also tried the flag "Have g++ follow the coming C++0x ISO language standard -std=c++0x"

    I have tried both at the same time and one at a time, no mas. I have also tried those commands manually.

    Another command I tried manually was -std=gnu++11 which was recommended in the thread header.


    --EDIT It seems like __cplusplus is < 201103L which is stated (or rather defined) in the thread header. This only happens when I manually use -std=c++11, for some reason C::B removes it if it was manually stated so I must use a check box to use this flag... --EDIT

    My compiler settings under the Toolchain Executables tab are as follows:

    C compiler: i686-w64-mingw32-gcc-4.8.1.exe

    C++ compiler: i686-w64-mingw32-c++.exe

    Linker for dynamic: i686-w64-mingw32-c++.exe

    Linker for static: ar.exe

    Debbuger: GDB/CDB debugger: default

    Resource compiler: windres.exe

    Make Program: mingw32-make.exe

    I have tried using other executables in the bin folder and still no luck... I'm starting to wonder if GCC supports C++11 or threading !?

    Has anyone been able to get threads to work with MinGW GCC, Code blocks or in general? If so how did you do it? Any links that might help? Any advice?

    P.S. I know there are other ways of threading like posix or other SDK's like SFML (I have successfully tried threading with this). But I want to use GCC threading and I'm quite baffled as to why it is so hard to do seeing as all the necessary files are there...

    --EDIT I have found that when I manually compile the program outside of Code Blocks I still get the same errors, whether I use g++ c++ or i686-w64-mingw32-g++/c++

    here is the command I run to build the files:

    C:\MinGW\mingw32\bin>g++.exe -D__GXX_EXPERIMENTAL_CXX0X__ -o0 -g3 -Wall -c -fmes sage-length=0 -std=c++11 -Wc++11-compat -o obj\Debug\main.o "F:\C Projects\Code Blocks\thread\main.cpp"

    still returns error: 'thread' is not a member of 'std'

    Could this be a bad build? I will try other revisions... --EDIT

  • allegory
    allegory over 10 years
    Yes, I did mean 4.8.1 thank you it's been a long day ;) That's great that it supports it but then why am I having such trouble getting this thing to build?
  • David G
    David G over 10 years
    Then I think it would be safe to say that either a) your compiler implementation is not truly 4.8.1 b) it is broken, or c) you are not passing it some flags it expects. Under Linux the -pthread compiler flag needs to be passed so there may be an analogous problem. If you are using the current trunk version of MinGW you will need to ensure that it does in fact have a thread model associated with it (both Mac and Linux gcc use POSIX threads by default, for example.)
  • DanielKO
    DanielKO over 10 years
    IIRC the similar option for -pthread on windows is -mthread, but its abscence should hide std::mutex, just produce linker errors or broken code.
  • allegory
    allegory over 10 years
    Daniel, I have tried -pthread (with -std=c++11) still throws the same error. I have tried -mthread (with -std=c++11) and it did not recognize it. maybe -wthread? David, the thread model associated with it is Win32 (I can see this with a gcc -v). I'd rather keep it win32 unless I absolutely must use posix. I too wonder if there is compiler flags that I am missing, which sounds like the true problem. Thanks again for your help, everyone!
  • allegory
    allegory over 10 years
    If it helps here is the output of the build with some of the flags I've tried (still has not worked :( ) : i686-w64-mingw32-g++.exe -Wall -g -std=c++11 -pthread -c "F:\C Projects\Code Blocks\thread\main.cpp" -o obj\Debug\main.o

Related