見出し画像

Android で cc !?

以前、「Android で Linux !?」を書いたのだけど、そこから cc を実行するまでが七転八倒。
挙げ句、ようやくできました。
通勤途中の電車の中で、cc やら vi やらをインストールして( Wi-Fi じゃないのに!)、コーディング(笑)。
コンパイルエラーを出しまくって(「Hello World」ごときで!)修正して完了。
「a.out」(懐かしい・・・)を実行。

感無量(しみじみ)。

30年くらい前に、ノートパソコンに携帯をつないで、はじめて新幹線からメールしたときも感無量だったなぁ。

コーディングから。

~ $ vi test.c
~ $ cat test.c
main()
{
        printf("Hello world!¥n");
}

怒られた。
main の型がない
printf の型がわからない
printf は <stdio.h> をインクルードするか型宣言が必要
だと。

~ $ cc test.c
test.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
main()
^
test.c:3:2: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
        printf("Hello world!¥n");
        ^
test.c:3:2: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
2 warnings generated.

修正。
まずは main の型修正。

~ $ !vi
~ $ vi test.c
~ $ !cat
~ $ cat test.c
int main()
{
        printf("Hello world!¥n");
}

当然、まだ怒られる。

~ $ cc test.c
test.c:3:2: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
        printf("Hello world!¥n");
        ^
test.c:3:2: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
1 warning generated.

修正。
<stdio.h> をインクルード。

~ $ vi test.c
~ $ cat test.c
#include <stdio.h>
int main()
{
        printf("Hello world!¥n");
}

コンパイルOK。
「a.out」が出来上がり。

~ $ cc test.c
~ $ ls
a.out  test.c

「a.out」を実行。
また怒られた。
「a.out」なんか知らない、と。

~ $ a.out
No command a.out found, did you mean:
 Command aapt in package aapt
 Command abook in package abook
 Command alist in package alist
 Command ant in package ant
 Command apt in package apt
 Command at in package at
 Command acat in package atool
 Command await in package await
 Command broot in package broot
 Command cut in package coreutils
 Command host in package dnsutils
 Command dot in package graphviz
 Command hmount in package hfsutils
 Command hut in package hut
 Command opt in package llvm
 Command count in package llvm-tools
 Command xfont in package mesa-demos
 Command most in package most
 Command mmount in package mtools
 Command tput in package ncurses-utils
 Command route in package net-tools
 Command pamcut in package netpbm
 Command atob in package nss-utils
 Command plot in package plotutils
 Command proot in package proot
 Command mount in package termux-tools
 Command mpost in package texlive-bin
 Command vcut in package vorbis-tools
 Command xhost in package xorg-xhost

「./a.out」で実行。

~ $ ./a.out
Hello world!¥n

「¥n」
う、う、
「\n」に修正。

~ $ vi test.c
~ $ cat test.c
#include <stdio.h>
int main()
{
        printf("Hello world!\n");
}

コンパイル、実行。
OK!

~ $ cc test.c
~ $ ls
a.out  test.c
~ $ ./a.out
Hello world!

さて。
alias 定義しようかな~。
タブ8も4に変えたいなぁ。

この記事が気に入ったらサポートをしてみませんか?