bombtrash bombtrash - 4 months ago 29
C Question

How to add flags to compiler in code blocks?

I am not sure if the question is framed correctly. But I am using code blocks on a windows machine. I want to use

gcc -o myfile myfile.c -lpthread
. But in my code blocks I don't have this -lpthread flag(is that called a flag?). So where do I need to add this in code blocks so that when I click build, it will simply call
gcc -o myfile myfile.c -lpthread
.

Answer

In codeblocks 16.01, you can specify the library you want to link (in this case libpthread.so) via Settings > Compiler... > Linker Settings > Add

Then you need to add the location of libpthread.so via locate libpthread.so

In this case, you may also need to specify -D_REENTRANT compiler flag to tell gcc about necessary headers for thread usage.