Loose-Info.com
Last Update 2021/12/24
TOP - 各種テスト - gcc - -iwithprefix ディレクトリ名 (-iwithprefixbefore)

-iwithprefix ディレクトリ名
-iwithprefixbefore ディレクトリ名
-iprefixオプションで指定した接頭辞に ディレクトリ名を追加したディレクトリをインクルード検索パスに追加

テスト概要

-iwithprefix、および-iwithprefixbeforeオプションを使用したコンパイル

実行環境

GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1


コード例・出力内容中の表記

・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。

使用ファイル

使用ファイル一覧
. +--header_dir_sample |   +--sample.h | +--header_dir_system |   +--stdio.h | +--sample.c

header_dir1/sample.h
#ifndef SAMPLE_H #define SAMPLE_H #include <stdio.h> #endif /* SAMPLE_H */

header_dir_system/stdio.h
/usr/include/stdio.hを上記ディレクトリにコピー
インクルードガードを一部変更
#ifndef _STDIO_H #define _STDIO_H 2 <--- 変更(元ファイルは1)

sample.c
#include "sample.h" int main(void) { printf("sample\n"); printf("_STDIO_H = %d\n", _STDIO_H); return 0; }

動作テスト

-iwithprefix、および-iwithprefixbeforeオプションを使用したコンパイル
$ gcc -v -iprefix header_dir \ > -iwithprefix _system -iwithprefixbefore _sample sample.c Using built-in specs. /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 ... #include "..." search starts here: #include <...> search starts here: header_dir_sample header_dir_system /usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include /usr/local/include /usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include-fixed /usr/include End of search list. as -v --64 -o /tmp/ccJqRcIX.o /tmp/ccKinTNQ.s /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/collect2 ... $ ./a.out sample _STDIO_H = 2 $ -iprefixオプションにより接頭辞「header_dir」を指定 -iwithprefixbeforeによる指定(ピンク)「header_dir」+「_sample」 -iwithprefixによる指定(青色)「header_dir」+「_system」