Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add compiler flags on codeblocks

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.

like image 685
user3201708 Avatar asked Oct 19 '15 07:10

user3201708


People also ask

How do I add a compiler flag in Visual Studio?

In Visual Studio You can set compiler options for each project in its Visual Studio Property Pages dialog box. In the left pane, select Configuration Properties, C/C++ and then choose the compiler option category.

How do I find my compiler in Code::Blocks?

On the Code::Blocks menu, go to "Settings", next click on "Compiler and Debugger...". This will open the "Compiler and debugger settings dialog". Under "Selected compiler" select the name of the compiler you are using. For most of you it will be "GNU GCC Compiler".

Where is GCC compiler in Code::Blocks?

Go to http://www.codeblocks.org/downloads and click Binary Release. Choose the installer with GCC Compiler, e.g., codeblocks-17.12mingw-setup.exe which includes MinGW's GNU GCC compiler download and GNU GDB debugger with Code::Blocks source files.


2 Answers

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.

like image 56
Michi Avatar answered Sep 18 '22 06:09

Michi


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.

like image 30
M.M Avatar answered Sep 21 '22 06:09

M.M