0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

-isystem /usr/include すると gcc 6.1 以上だと stdio.h などが見つからずにエラーになるので注意

Last updated at Posted at 2019-11-05

背景

CMake でライブラリが INTERFACE_INCLUDE_DIRECTORIES で /usr/include/OpenEXR/.. を設定している.
このライブラリを IMPORTED として自前アプリに組み込んでいる.

この場合, INTERFACE_INCLUDE_DIRECTORIES のパスが -I ではなく, -isystem を使う.

-isystem /usr/include/OpenEXR/.. がコンパイルのコマンドラインになる.

この設定により, include_next で stdio.h などがみつらなくてコンパイルエラーになる.

原因

-isystem on a system include directory causes errors
https://stackoverflow.com/questions/37218953/isystem-on-a-system-include-directory-causes-errors

include_next などとの絡みです.

https://qiita.com/angel_p_57/items/34c42bbb38e81178bdc1
https://www.poared.com/wordpress/?p=133
https://gcc.gnu.org/onlinedocs/gcc-3.2.3/cpp/Wrapper-Headers.html

ありがとうございます.

相対パス指定, たとえば -isystem /usr/include/OpenEXR/.. でも同じです.

結果として, -isystem /usr/include/ とすると, include_next でのヘッダのサーチパスの探索順序が変わるなどして, エラーになります.

-I/usr/include では問題ありません(-I/usr/include は include_next の探索では無視(?)されるらしいからです).

cmake での解決 

imported なターゲットで INTERFACE_INCLUDE_DIRECTORIES を使っている場合, デフォルトでは SYSTEM(-isystem)になる.

-DCMAKE_NO_SYSTEM_FROM_IMPORTED:BOOL=TRUE を設定し, SYSTEM にしないようにする.

本質的な解決

/usr/include のパスを追加しない.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?