Author Topic: Strange behaviour with Gcc4.8 and C++11  (Read 9572 times)

Offline koala01

  • Single posting newcomer
  • *
  • Posts: 7
Strange behaviour with Gcc4.8 and C++11
« 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:
  • Gcc 4.8.0 (20130217)
  • windows vista 64 bits
  • svn "trunk" revision of mingw-w64
  • svn "experimental" version of winpthread for thread support

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Online stahta01

  • Lives here!
  • ****
  • Posts: 7682
    • My Best Post
Re: Strange behaviour with Gcc4.8 and C++11
« Reply #2 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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline koala01

  • Single posting newcomer
  • *
  • Posts: 7
Re: Strange behaviour with Gcc4.8 and C++11
« Reply #3 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 ?

Online stahta01

  • Lives here!
  • ****
  • Posts: 7682
    • My Best Post
Re: Strange behaviour with Gcc4.8 and C++11
« Reply #4 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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org