Kam
Kam

Reputation: 6008

How can I exclude a file from g++ compiler options

I'd like to compile most of my code with -Wconversion -Werror.

The problem is that I use a .cpp file that is open source and should not be modified, and compiling it with those flags fails because that specific .cpp file has issues with some "implicit conversions that may alter a value".

Can I somehow instruct the build to compile all other files with -Wconversion -Werror but compile that file without those flags?

Upvotes: 1

Views: 2096

Answers (1)

hardmath
hardmath

Reputation: 8823

The make utility provides a rich set of facilities for customizing builds and for defaulting to implicit procedures for things that are routine logic. The GNU make tutorial is a good starting point if there's a question related to the gcc toolchain.

Essentially a makefile contains the custom logic for building a project. Rules consist of an apparent target separated from the dependencies by a colon on one line, and then (possibly zero or many) recipes on succeeding lines indented by a tab character that explain steps in building that target. Bogus targets, eg. clean, may also be defined for convenience in maintaining a project.

If there's a target-specific rule, that will be used in preference to any implicit rule to build that target. Probably the OP only needs to add a target-specific rule to an existing makefile that will govern the use of compiler options (building the object from the source).

Upvotes: 1

Related Questions