anon
anon

Reputation:

Make - "Treat warning as error" for specific files

I'm currently working on a Makefile project, and since I'm using boost, I have tons of warnings during compilation, so I can't just enable -Werror in my entire build. However, I have a set of logging macros that effectively wrap printf() for me so I can have a prefix in all logging statements that includes line number, file base name, and a custom prefix.

I want to avoid potential bugs down the line, such as invalid logging statements which could potentially crash the software down the line (ie: a debug warning statement which seldom occurs causing a segfault).

Is it possible to pass an argument to make to have all instances of certain functions, or at least all macros defined in a header file, to treat warnings as errors?

Thank you.

Upvotes: 0

Views: 717

Answers (2)

tux3
tux3

Reputation: 7320

As far as I know there is no standard, portable way to do this, so the solution will depend on your compiler.

With GCC you can use Diagnostic Pragmas.
For example #pragma GCC diagnostic error "-Werror" will enable Werror for the rest of the file.

Of course this is not portable, so if you use other compilers you'll want to wrap it in a #ifdef __GNUC__

Upvotes: 0

Juan
Juan

Reputation: 188

You can with

#pragma warning (error: 0001)

Where 0001 is the warning you want to be an error

Upvotes: 1

Related Questions