Linux開発環境の構成実験
実験の目的:
1.1 Linuxオペレーティングシステムでのアプリケーション開発プロセスの理解
1.2
銃器ツールチェーンの使用の習得1.3 gdbデバッグスキルの習得
実験的な内容:
テストユーザーを作成します。パスワードもテストです。
testでログインした後、srcディレクトリを作成します。すべてのソースコード、中間コード、およびターゲットコードが/ home / test / srcディレクトリに配置されます。
0からnまでの累積値を解決できる単純な合計関数を作成し、test2.cに保存します。
#include"test.h"
int test(int m)
{
int sum=a;
int i;
for(i=a;i<=m;i++)
{
sum+=i;
}
return sum;
}
メイン関数を記述してtest1.cに保存し、ウェルカムメッセージを出力するように依頼して、nの値を入力し、合計値(test2.cを呼び出す関数)を出力します。
#include<stdio.h>
#include"test.h"
int main()
{
int n;
scanf("%d",&n);
printf("%d",test(n));
}
ヘッダーファイルを記述します。マクロは、test.hに格納されている2つの関数の初期値を定義します。
#define a 0
int test(int);
Makefileを作成し、実行可能ファイルのテストを生成します。
test:test1.o test2.o
gcc test1.o test2.o -o test
test1.o:test1.c test.h
gcc -c test1.c -o test1.o
test2.o:test2.c test.h
gcc -c test2.c -o test2.o
clean:
rm -rf *.o test
次に、実行結果のスクリーンショットを見てみましょう。