Published Book on Amazon
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1 | |
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2 |
출판된 한글판 도서
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상) | |
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하) |
Original Book Contents
23.6.3 Saving, Compiling and Running Program
● Saving program
The created program is saved as a file. A source program written in C is stored in a file with extension of ".c". We will store the program to "~/program_test /test_inout.c" file. Now, if you check the folder contents where the file is located, it will show the results as follows.
pi@raspberrypi ~ $ cd program_test |
pi@raspberrypi ~/program_test $ ls –l |
-rw-r--r-- 1 pi pi 215 May 9 11:45 test_inout.c |
● Compiling program – "gcc" command
To run a program that has been writed completely, you must first compile the program and create an executable file. To do this, use "gcc" command.
[Command Format]
gcc -o <execute-file> <source-file> -l<external-head-file-folder> |
Let's compile the program you wrote. If there is an error in the program, error will be displayed as follows.
pi@raspberrypi ~/program_test $ gcc -o test_inout test_inout.c |
test_inout.c: In function ‘main’: test_inout.c:8:2: error: unknown type name ‘f’ test_inout.c:8:16: error: expected ‘)’ before string constant |
If there is no error in the developed program code, no message is output and an executable file is created. The following is confirming the result.
pi@raspberrypi ~/program_test $ ls –l |
-rwxr-xr-x 1 pi pi 5990 May 9 11:43 test_inout -rw-r--r-- 1 pi pi 215 May 9 11:45 test_inout.c |
● Executing program
The executable created here is "test_inout". If you look closely, you can see that the executable attribute is automatically granted to the file attribute. Now that you are ready to run the program, type path and executable file name as follows and run the program.
pi@raspberrypi ~/program_test $ ./test_inout |
Hello. input your number 5 The calculation result is as follows 50 |
If you enter a number in response to a prompt to enter the data, you will see that the program is executed normally.