android framework

android framework 升级第3天

2021-01-24  本文已影响0人  Blanchard

C 语言基础

Hello_World_Brian_Kernighan_1978.jpg

直接开始

mkdir -p ~/src/hello_c
cat>~/src/hello_c/hello.c<<EOF
#include <stdio.h>          /* header provide printf */
int main (int argc, char *argv[]) /* main entry function */
{
    printf("Hello World\n");/* to output the string on a display */
    return 0;
}
EOF
gcc -o hello.bin hello.c
./hello.bin

Makefile 版本

cat>>~/src/hello_c/Makefile<<EOF
# This is the default target, which will be built when 
# you invoke make
.PHONY: all
all: hello install

# This rule tells make how to build hello from hello.c
hello: hello.c
    gcc -o hello.bin hello.c

# This rule tells make to copy hello to the binaries subdirectory,
# creating it if necessary
.PHONY: install
install:
    mkdir -pv ~/bin
    cp -pv hello.bin ~/bin
    ~/bin/hello.bin

# This rule tells make to delete hello and hello.o
.PHONY: clean 
clean:
    rm -vf hello.bin
    rm -vf ~/bin/hello.bin
EOF
sed -i 's/    /\t/g' ~/src/hello_c/Makefile
make -C ~/src/hello_c 

参考

https://www.oreilly.com/library/view/c-cookbook/0596007612/ch01s16.html
https://en.wikipedia.org/wiki/%22Hello,_World!%22_program

上一篇 下一篇

猜你喜欢

热点阅读