Loose-Info.com
Last Update 2021/12/25
TOP - 各種テスト - gcc - -isysroot ディレクトリ

-isysroot ディレクトリ
ヘッダファイルのルートディレクトリとしてディレクトリを使用

テスト概要

-isysrootオプションを使用したコンパイル

実行環境

GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1


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

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

使用ファイル

使用ファイル一覧
. +-- sample.c +-- usr +-- include |   +-- stdio.h | +-- local +-- include +-- sample.h

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

usr/local/include/sample.h
#ifndef SAMPLE_H #define SAMPLE_H #define SAMPLE 1 #endif /* SAMPLE_H */

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

動作テスト

-isysrootオプションを使用したコンパイル
エラー回避のため、-idirafterにより最終段階での/usr/include内の検索を指定
$ gcc -v -isysroot ./ -idirafter /usr/include 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: /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 /usr/include End of search list. as -v --64 -o /tmp/ccebGBt6.o /tmp/cctG2FVr.s /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/collect2 ... $ ./a.out SAMPLE = 1 _STDIO_H = 2 $ 青色部は-isysrootにより指定したディレクトリ 「./usr/local/include」内のsample.hがインクルードされたため「SAMPLE = 1」を出力 「./usr/include」内のstdio.hがインクルードされたため「_STDIO_H = 2」を出力