Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Code::Blocks compiler options


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Storyyeller   Members   -  Reputation: 212

Like
0Likes
Like

Posted 17 January 2010 - 04:01 PM

I am making a game in C++ with Code::Blocks. I noticed that I was often getting bugs due to forgetting to return a value from a function, so I tried to make the compiler treat this as an error. However, I can't figure out how to do it. I tried putting -Werror=return-type under Other Options on the Build Options menu, but now it refuses to build at all. -------------- Build: Debug in Pickory --------------- mingw32-g++.exe -Wall -Werror=return-type -g -Wall -Wno-reorder -I..\Pickory -I..\zHeaders\BOX2D_21 -I..\zHeaders -IC:\ActiveProjects\zHeaders -c C:\ActiveProjects\Pickory\main.cpp -o obj\Debug\main.o cc1plus.exe: error: unrecognized command line option "-Werror=return-type" Process terminated with status 1 (0 minutes, 0 seconds) 0 errors, 0 warnings

Sponsor:

#2 mrjones   Members   -  Reputation: 612

Like
0Likes
Like

Posted 17 January 2010 - 07:25 PM

There is no such option, try running cc1plus with --help to get possible options listed. Also, why aren't warnings enough? With -Wall switch surely there are warnings when there is no return value from a function.

#3 phresnel   Members   -  Reputation: 949

Like
0Likes
Like

Posted 17 January 2010 - 08:50 PM

Quote:
Original post by Storyyeller
I am making a game in C++ with Code::Blocks. I noticed that I was often getting bugs due to forgetting to return a value from a function, so I tried to make the compiler treat this as an error.
However, I can't figure out how to do it.

I tried putting -Werror=return-type under Other Options on the Build Options menu, but now it refuses to build at all.



-------------- Build: Debug in Pickory ---------------

mingw32-g++.exe -Wall -Werror=return-type -g -Wall -Wno-reorder -I..\Pickory -I..\zHeaders\BOX2D_21 -I..\zHeaders -IC:\ActiveProjects\zHeaders -c C:\ActiveProjects\Pickory\main.cpp -o obj\Debug\main.o
cc1plus.exe: error: unrecognized command line option "-Werror=return-type"
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings


Code::Blocks is not a compiler, but an IDE that supports, beneath other, MinGW, which in turn is the windows port of GCC. Hence, you will find all supported command line options at http://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html#Invoking-GCC, there you'll find Warning-Options, and then, there is "-Werror" to treat warnings as errors, and as mrjones mentioned, "-Wall" to enable all standard options. Then there is "-Wextra", to get even more warnings. And to be even surer, you can also use "-pedantic", to make it even more strict vs. ISO, and "-pedantic-errors", to emit errors for -pedantic related warnings.

Oh, and you can save yourself from hardcoding options:


#4 Storyyeller   Members   -  Reputation: 212

Like
0Likes
Like

Posted 18 January 2010 - 02:53 AM

-Werror works, but I wanted to treat only one specific type of warning as an error.

So I tried to use the -Werror= option mentioned at http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options but it didn't work.


Quote:

-Werror=
Make the specified warning into an error. The specifier for a warning is appended, for example -Werror=switch turns the warnings controlled by -Wswitch into errors. This switch takes a negative form, to be used to negate -Werror for specific warnings, for example -Wno-error=switch makes -Wswitch warnings not be errors, even when -Werror is in effect. You can use the -fdiagnostics-show-option option to have each controllable warning amended with the option which controls it, to determine what to use with this option.



I don't want it to treat all warnings as errors, because I am using Box2d, which has tons of spurious warnings in its headers, and I don't feel like rewriting the whole library myself.

#5 phresnel   Members   -  Reputation: 949

Like
0Likes
Like

Posted 18 January 2010 - 04:48 AM

I guess return-type is not about not returning from a function, but about misuse of the return-type, e.g. return .0f where the return type is actually int.

I don't know if you can disable/enable that mistake you look for in particular, but what is wrong with -Wall? It gives you a list of all warnings, which are there for a reason. Then, in case there are 159467821345 errors, you could still text-search the list.

#6 Storyyeller   Members   -  Reputation: 212

Like
0Likes
Like

Posted 18 January 2010 - 10:57 AM

Looking through hundreds of warnings every single time I make a change to the program is kind of a pain.

It would be so much simpler to get it to automatically stop the build process when it encounters certain warnings.

#7 phresnel   Members   -  Reputation: 949

Like
0Likes
Like

Posted 18 January 2010 - 08:22 PM

Quote:
Original post by Storyyeller
Looking through hundreds of warnings every single time I make a change to the program is kind of a pain.

Quote:
Original post by phresnel
Then, in case there are 159467821345 errors, you could still text-search the list.




Quote:
It would be so much simpler to get it to automatically stop the build process when it encounters certain warnings.

While it seems you can enable/disable your particular warning wish, you can also -Werror -Wfatal-errors and fix warnings step by step.

Why exactly don't you want to fix all warnings? It is annoying, but something you should always do, if you are interested in good code (and good programmers are interested in good code :)).


edit: Ah, I was so wrong about return-type.

Test this snippet with -Werror=return-type -Wfatal-errors (== treat no return type as error, abort upon error)
#include <stdio.h>
int u () {
printf("%d", .5f); // will give you a format warning
} // gives you an error for missing return, and stops

int v () {
printf("%d", .5f); // nothing, compilation stopped already
} // nothing, compilation stopped already



I also see now most of your warnings come from Box2d. In that case, there would be those pragmas, where you can nitpick-disable some warnings (#pragma ... #include ... #pragma):

#pragma GCC diagnostic ignored "-Wformat"
int u () {
printf("%d", .5f); // nothing
return 0;
}
#pragma GCC diagnostic enable "-Wformat"



edit2: And there is -fdiagnostics-show-option, which will make gcc print the proper switch for each diagnostic it emits. You could use that option to see which warnings are produced by Box2d, and then disable them using above pragma.



[Edited by - phresnel on January 19, 2010 2:22:48 AM]




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS