Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid apply compilation flag for third party header

Tags:

c++

gcc

cmake

eigen

We want to add -Werror=conversion to our code base, but the header of the Eigen library will trigger a lot of these error. I am wondering what is the best approach here so that the compilation flag only applies to our code but not for third party header.

One solution we are thinking is to create a wrapper library for Eigen that only contains stuff we need. We will compile the wrapper without the flag. But this is a somewhat big undertaking. I am wondering if there are other solutions.

like image 811
auzn Avatar asked Oct 23 '25 11:10

auzn


2 Answers

With gcc you can include Eigen headers via -isystem. They will be treated like system headers and no warnings will be reported. This silences all warnings, though with well tested 3rd party libraries this is usually ok.

like image 115
463035818_is_not_a_number Avatar answered Oct 25 '25 01:10

463035818_is_not_a_number


You can create a header Eigen.h with this:

#pragma once

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif

#include <Eigen/Core>
// ...

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
like image 45
bitmask Avatar answered Oct 25 '25 02:10

bitmask