Page 1 of 2

Enabling c++11

Posted: Fri Feb 22, 2013 1:29 am
by jd2014
Hi,
I am using codelite v5.0.6013 and trying to synchronize multiple threads that are modifying a common set of data hanging off a linked list.
When I add the line "#include <thread>, there is a warning message as shown below:
This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
Seemed straightforward enough so...
Since I'm using g++, I placed the flag "-std=c++11" in the settings->build_settings->compiler and linker options.
However, those options showed no effect on subsequent builds.
So my question is:
How to I enable the c++11 options?
Thanks and best regards,
JD

Re: Enabling c++11

Posted: Fri Feb 22, 2013 2:33 am
by jd2014
I discovered that adding the snippet below allows the the thread include file.
#ifndef _GLIBCXX_THREAD
#define _GLIBCXX_THREAD = 1
#endif
#include <thread>


However, when I try to do the below, it tells me "thread" is not in the std namespace.
case 1: std::thread task1(T);
break;
Yet thread shows up in the auto-fill editing for the std namespace.
So... I'm still diddling with it.
Any ideas would be appreciated.
Regards,
JD

Re: Enabling c++11

Posted: Fri Feb 22, 2013 12:48 pm
by eranif
You fail to mention your OS and your compiler version
HOW TO POST

Eran

Re: Enabling c++11

Posted: Fri Feb 22, 2013 4:14 pm
by jd2014
I am developing this under Win7 64bit system.
Not sure about compiler version or how to get it...
So, I placed the -v option on the command line revealing:
make 3.82.90
Built for i686-w64-mingw32


Surely I'm missing somthing basic, after all, this is my first forray into Codelite.
Oh, and btw, I am not going to place qualifiers before the <include> files.
It may have gotten them to load, but it should not and will not be necessary if the compiler option is correct.
Thanks and best regards,
JD

Re: Enabling c++11

Posted: Fri Feb 22, 2013 4:17 pm
by eranif
From what I have read and investigated so far, MinGW-TDM GCC4.7.1 does not support std::thread...
You might want to try boost::thread instead

Eran

Re: Enabling c++11

Posted: Fri Feb 22, 2013 5:04 pm
by jd2014
Oh me... boost eh?
Heard of it but never used it.
Any suggestion as to installing and activating it in Codelite?
JD

Re: Enabling c++11

Posted: Fri Feb 22, 2013 5:20 pm
by eranif
Personally, I dont use boost (too bloated for my taste)
When I need threads, I am using wxThread (part of wxWidgets) or QThread (part of Qt) - depends on the project

Or you can always use pthread_* API (which is supported with MinGW) and is cross platform
here is an example of using pthread:

Code: Select all

#include <iostream>
#include <stdio.h>
#include <pthread.h>

void* start_here(void * args)
{
    printf("hello from thread\n");
    return NULL;
}

int main() {
    pthread_t threadId;
    pthread_create(&threadId, NULL, start_here, NULL);
    printf("hello world\n");
    pthread_join(threadId, NULL);
    return 0;
}
This sample will compile on all major OSs.
You will need to add "pthread" to the linker libraries (project settings -> linker -> libraries"
Eran

Re: Enabling c++11

Posted: Fri Feb 22, 2013 5:53 pm
by jd2014
Well ratts. I had my heart set on using the c++11 library.
I suppose I can revert to pthreads - if I must.

You said I needed to add pthread to project settings->linker->libraries. Can't see it.
I do see a path to project settings->build_settings->linker_options.
JD

Re: Enabling c++11

Posted: Fri Feb 22, 2013 6:14 pm
by jd2014
oops... found the linker libries...
Hmmm, wouldn't you know it; now there is a error on the build...

Here is the source line you recommended (
I changed start_here to a little snippet named "hello"
):

Code: Select all

pthread_create(&threadId, NULL, hello, NULL);
Apparently it is complaining about the last NULL.

Here is the error generated:
C:/C++ FD/BUDGETS/FundTransfers/bank.cpp:700:49: error: invalid conversion from 'void (*)()' to 'void* (*)(void*)' [-fpermissive]

Oh me... I hate to have someone debug something for me.
But until I get more adept at codelite, a little hand holding is appreciated.
JD

Re: Enabling c++11

Posted: Fri Feb 22, 2013 6:17 pm
by eranif
1.png
See in the screenshot what I meant
Eran