8

I've been trying to compile a simple multithreaded piece of code I found online in an effort to learn how to multithread.
To run this piece of code I need to use the compiler flags: -pthread and -std=c++0x.
But whenever I try to add the flags the build log doesn't show them being used.

I've tried some generic tips online to get these to work, but none of them worked. Can someone help?

I've tried other advice online to add compiler flags to code blocks, but when I do that and check the build log none of them appear.

Suraj Jain
  • 4,463
  • 28
  • 39
user3201708
  • 91
  • 1
  • 1
  • 5

4 Answers4

14

Because This Question was marked as Duplicate, even if doesn't have to do with it, because there is about Linker Flag and here is about Compiler Flags, I will post My answer HERE.

You will have to go to Settings -> Compiler... and next you'll have to click on Linker Settings TAB.

On the right side you will see Other Linker Options. There you have to type -lpthread and press OK.

You may need to click on rebuild after that.

Community
  • 1
  • 1
Michi
  • 5,175
  • 7
  • 33
  • 58
4

Open your project and then go Project > Build Options > Compiler Flags .

You can tick boxes in the "Compiler Flags" tab, and you can write other options in the "Other Options" tab.

Do one or the other, e.g. don't tick the "-std=c++98" box and also put "-std=c++11" in the Other Options. This will end up in both options being passed to the compiler.

M.M
  • 138,810
  • 21
  • 208
  • 365
  • That's what I've been trying, the flags aren't actually used for some reason. – user3201708 Oct 19 '15 at 07:50
  • Suppose I am not creating any project and building single .C/.CPP file in Codeblocks (using Default GCC compiler). I can go to settings and do many custom settings. But I cannot figure out how to add post build options such as knowing the size of object code without creating any project. – Rajesh Oct 26 '17 at 05:59
1

Another option instead of using the "other options" is to create a custom compiler flag. So in addition to a compiler flag, you can specify a linker flag. In the case of the -pthread (which I also was having trouble with) it looked like it needed the linker flag as well, as mentioned by Michi One can create a new compiler flag by right clicking and selecting the new option

0

add options: menu->project->properties->Build targets tab->Build options button