Enabling c++11

CodeLite installation/troubleshooting forum
jd2014
CodeLite Curious
Posts: 9
Joined: Thu Feb 07, 2013 1:18 am
Genuine User: Yes
IDE Question: C++
Contact:

Enabling c++11

Post 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
jd2014
CodeLite Curious
Posts: 9
Joined: Thu Feb 07, 2013 1:18 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Enabling c++11

Post 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
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Enabling c++11

Post by eranif »

You fail to mention your OS and your compiler version
HOW TO POST

Eran
Make sure you have read the HOW TO POST thread
jd2014
CodeLite Curious
Posts: 9
Joined: Thu Feb 07, 2013 1:18 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Enabling c++11

Post 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
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Enabling c++11

Post 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
Make sure you have read the HOW TO POST thread
jd2014
CodeLite Curious
Posts: 9
Joined: Thu Feb 07, 2013 1:18 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Enabling c++11

Post by jd2014 »

Oh me... boost eh?
Heard of it but never used it.
Any suggestion as to installing and activating it in Codelite?
JD
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Enabling c++11

Post 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
Make sure you have read the HOW TO POST thread
jd2014
CodeLite Curious
Posts: 9
Joined: Thu Feb 07, 2013 1:18 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Enabling c++11

Post 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
jd2014
CodeLite Curious
Posts: 9
Joined: Thu Feb 07, 2013 1:18 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Enabling c++11

Post 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
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Enabling c++11

Post by eranif »

1.png
See in the screenshot what I meant
Eran
You do not have the required permissions to view the files attached to this post.
Make sure you have read the HOW TO POST thread
Post Reply