C言語を勉強するにあたりEmacsの設定やコンパイル・Maikefileなどやってみた。
Emacsの設定
行終了の";" と "return key" でオート改行+インデント、それから"C-c c"でコンパイルできるようにする。
emacs.elに以下追加。
;;; C (add-hook 'c-mode-common-hook '(lambda () (c-toggle-auto-hungry-state 1) (define-key c-mode-base-map "\C-m" 'newline-and-indent) (define-key mode-specific-map "c" 'compile) ))
実行してみる
とりあえず"zeon.c"ファイルを作成して下記を書く。
# include <stdio.h> int main() { printf("Sieg Zeon!\n"); return 0; }
emacsで"C-c c"でミニバッファに
Compile command: make -k
と表示されるから
Compile command: make -k zeon
もしくは
Compile command: gcc -o zeon zeon.c
として実行。
emacsで"M-x shell"でshellを起動。lsでディレクトリを見てみる。
zeon.c" zeon
"zeon.c"ファイルと同じ階層に、"zeon"ができてるはず。(エラーでなければ)
shellで
./zeon
と打って実行
Sieg Zeon!
と表示される。
メイクファイル
『http://www.c.csce.kyushu-u.ac.jp/~seiichirou/wiki/index.php?Makefile%A4%CE%BD%F1%A4%AD%CA%FD』を参考にMakefileもやってみる。
新しく"zeon2.c"を作成して下記を書く。
# include <stdio.h> int main() { printf("Sieg Zeon! Sieg Zeon!\n"); return 0; }
同じ階層に"Makefile"ファイルを作成して以下書き込む。
# Makefile zeon2: zeon2.c gcc -o zeon2 zeon2.c
そしてemacsで"C-c c"
Compile command: make -k
で、"zeon2"ができる。
./zeon
で、実行
Sieg Zeon! Sieg Zeon!
OK(・∀・)b