Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: koala01 on March 04, 2013, 01:02:10 pm

Title: Strange behaviour with Gcc4.8 and C++11
Post by: koala01 on March 04, 2013, 01:02:10 pm
Hello...

I just have compiled a personnal version of Gcc 4.8 with C++11 threads support.

When i compile a simple code like
Code
#include <thread>
#include <iostream>

void doSomeWork( )
{
    std::cout << "hello from thread..." << std::endl;
    return;
}
int main( int argc, char *argv[] )
{
    std::thread t( doSomeWork );
    t.join();
    return 0;
}
directly from the windows command line with the correct options ( -static -std=c++11 <-m32>) , i have no problem : calling the executable just works fine.

If i compile the same code with the same options under C::B, execution fails on a std::system_error exception ("Enable multithreading to use std::thread : operation non permitted" )

has someone an idea on what' appens?

PS:
Title: Re: Strange behaviour with Gcc4.8 and C++11
Post by: oBFusCATed on March 04, 2013, 01:30:38 pm
Start from here: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F
Title: Re: Strange behaviour with Gcc4.8 and C++11
Post by: stahta01 on March 04, 2013, 01:42:33 pm
FYI:

After verifying the compiler command is exactly the same (including options are in the same order).

You will want to confirm the PATH being set to the same as CB does it is not the cause of the issue.

Tim S.
Title: Re: Strange behaviour with Gcc4.8 and C++11
Post by: koala01 on March 05, 2013, 02:21:13 am
i have just understood where  is the probelm:

When compiling a c++ project, C::B calls g++ two time:
a first time to create the object file with command
Code
g++ -std=c++11 -static -c main.cpp -o main.o
(which is exactly the correct command we need)
and a second time to link the object file in an executable with the command
Code
g++  -o programName.exe programName.exe
This is a normal behaviour since projects are, usually, composed by more than one single file ;)

If Gcc has been build with (e g) --enable-shared, programs are by default linked with ... dll libraries version

As far as i know, it seems that there is a known problem when linking with shared libraries for stdc++ and winpthread.

But, as the problem can be resolved if linking is done with a command like
Code
g++ -static -o programName.exe main.o
it would (maybe) be interresting to ensure that -static option (if present) is correctly passed when using g++ for linking.

What do you thing about ?
Title: Re: Strange behaviour with Gcc4.8 and C++11
Post by: stahta01 on March 06, 2013, 04:02:49 pm
it would (maybe) be interresting to ensure that -static option (if present) is correctly passed when using g++ for linking.

What do you thing about ?

Yeah, it would be boring if we required people to put Linking Options in the place for Linker options.

Tim S.

PS: I prefer boring.