0

I have searched through forums here, but nothing helped to the end in my case. I'm trying to write and compile some C++ multithreading code in Code::Blocks 13.12, for now the only code I have is:

#include <iostream>
#include <thread>

void cpp11()
{
    std::cout<<"C++11 MULTITHREADING\n";
}

int main()
{
    std::thread t(cpp11);
    t.join();
}

Initially I could not compile and run that code (both in Code::Blocks and Terminal) because I was getting an error:

Terminate called after throwing an instance of 'std::system_error' what(): Enable multithreading to use std::thread: Operation not permitted.

I found that I'm able to compile and run that code calling g++ in the Terminal like that:

g++ -std=c++11 -pthread main.cpp -o Program

but I cannot set the same in Code::Blocks. I went to Project -> Build options, in the Compiler settings tab I selected Have g++ follow the C++11 ISO C++ language standard [-std=c++11]. In the Compiler settings -> Other options I typed -pthread. In Linker settings -> Other linker options I typed -pthread. It does not work, after I build and run my project in Code::Blocks I get the same error message.

Thank you for any help!

Dawid Sibiński
  • 1,657
  • 3
  • 21
  • 40

1 Answers1

0

Follow instructions for this question

How do I link to a library with Code::Blocks?

in the last step, when Add library dialog pops up type pthread.

UPDATE

Again go to build options > Compiler settings . click on other options and type -pthread

Community
  • 1
  • 1
Roozbeh
  • 462
  • 3
  • 14
  • I just did like you advised - it did not help. pthread is added but is still gives me the same error. – Dawid Sibiński May 07 '15 at 13:14
  • @ikS11 can copy and paste commands that code blocks run to here? you can see them in build log. – Roozbeh May 07 '15 at 13:56
  • Here you have the Build log's output after build and run: Checking for existence: /home/dawid/MyProject/bin/Debug/MyProject Executing: xterm -T MyProject -e /usr/bin/cb_console_runner LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. /home/dawid/MyProject/bin/Debug/MyProject (in /home/dawid/MyProject/.) Process terminated with status 0 (0 minute(s), 2 second(s)) – Dawid Sibiński May 07 '15 at 14:09
  • Eh, some fun happened.... I changed the settings as you advised, but I did not change anything in the code, so the code was not build from the beginning... Works perfectly fine now after rebuild, thank you! – Dawid Sibiński May 07 '15 at 14:11