From 77ab0e7c2ad0af22934d78d56d01347de11ade29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerardo=20Marx=20Ch=C3=A1vez-Campos?= Date: Sat, 24 Apr 2021 14:10:56 +0000 Subject: [PATCH 1/2] Adding C code and instructions on Redmen --- Readme.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 4ad9946..836bfa6 100644 --- a/Readme.md +++ b/Readme.md @@ -1,4 +1,24 @@ # Lecture 4: An overview of C and C++ A long this lecture let us test two basic Hello World scripts on C and C++, respectively. The idea is to remember the compilation chain process to obtain an executable application. -## C-code +## The Hello-Wolrd on C +The code used for this example is +```c +//Gerardo Marx 24/04/2021 + #include + int main(int argc, char *argv[]){ + printf("Hello World from BeagleBoard!!\n"); + return 0; + } +``` + +then to compile on an executable code use +```bash +$ gcc hello-world.c -o +``` +here the `` is the name that you want for your executable code. + +Now it is possible to execute your new code by using: +```bash +$ ./ +$ Hello World from BeagleBoard!! \ No newline at end of file From c0aae5e38217f04a49125e9e7d270cf4b3a74e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerardo=20Marx=20Ch=C3=A1vez-Campos?= Date: Sat, 24 Apr 2021 16:24:32 +0000 Subject: [PATCH 2/2] Adding chain process to Readme --- Readme.md | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 836bfa6..177485a 100644 --- a/Readme.md +++ b/Readme.md @@ -21,4 +21,94 @@ here the `` is the name that you want for your executable code. Now it is possible to execute your new code by using: ```bash $ ./ -$ Hello World from BeagleBoard!! \ No newline at end of file +$ Hello World from BeagleBoard!! +``` + +## The Chain process + +In some cases you will need to get access to the intermediate files that are produced by your code during the compilation process. Thus, following the next steps you can obtain the processed, assambled and output files. + +```bash +➜ l4-CAndCpp git:(master) ls -l +total 32 +-rw-r--r-- 1 debian debian 231 Apr 24 13:28 Readme.md +-rwxr-xr-x 1 debian debian 8144 Apr 24 13:33 hello-c +-rw-r--r-- 1 debian debian 137 Apr 24 13:33 hello-world.c +-rw-r--r-- 1 debian debian 183 Apr 24 13:49 hello-world.cpp +-rwxr-xr-x 1 debian debian 8944 Apr 24 13:58 hellocpp +➜ +➜ l4-CAndCpp git:(master) g++ -E hello-world.cpp > processed.cpp +➜ l4-CAndCpp git:(master) ✗ ls -l +total 688 +-rw-r--r-- 1 debian debian 231 Apr 24 13:28 Readme.md +-rwxr-xr-x 1 debian debian 8144 Apr 24 13:33 hello-c +-rw-r--r-- 1 debian debian 137 Apr 24 13:33 hello-world.c +-rw-r--r-- 1 debian debian 183 Apr 24 13:49 hello-world.cpp +-rwxr-xr-x 1 debian debian 8944 Apr 24 13:58 hellocpp +-rw-r--r-- 1 debian debian 668283 Apr 24 15:42 processed.cpp +``` +then, by using the `less` command you visualize the file's content +```bash +# 1 "hello-world.cpp" +# 1 "" +# 1 "" +# 1 "/usr/include/stdc-predef.h" 1 3 4 +# 1 "" 2 +# 1 "hello-world.cpp" + + +# 1 "/usr/include/c++/8/iostream" 1 3 +# 36 "/usr/include/c++/8/iostream" 3 +``` +by pressing the `SPC` key you will continue to the next lines, and by pressing the `q` key you will quit and close the file exploration through `less` command. + +The same can be done for the assambled file: +```bash +➜ l4-CAndCpp git:(master) ✗ g++ -S processed.cpp -o helloworld.s +➜ l4-CAndCpp git:(master) ✗ ls -l +total 692 +-rw-r--r-- 1 debian debian 231 Apr 24 13:28 Readme.md +-rwxr-xr-x 1 debian debian 8144 Apr 24 13:33 hello-c +-rw-r--r-- 1 debian debian 137 Apr 24 13:33 hello-world.c +-rw-r--r-- 1 debian debian 183 Apr 24 13:49 hello-world.cpp +-rwxr-xr-x 1 debian debian 8944 Apr 24 13:58 hellocpp +-rw-r--r-- 1 debian debian 3191 Apr 24 16:19 helloworld.s +-rw-r--r-- 1 debian debian 668283 Apr 24 15:42 processed.cpp +``` + +and for the output file: +```bash +➜ l4-CAndCpp git:(master) ✗ g++ -c helloworld.s +➜ l4-CAndCpp git:(master) ✗ ls -l +total 696 +-rw-r--r-- 1 debian debian 231 Apr 24 13:28 Readme.md +-rwxr-xr-x 1 debian debian 8144 Apr 24 13:33 hello-c +-rw-r--r-- 1 debian debian 137 Apr 24 13:33 hello-world.c +-rw-r--r-- 1 debian debian 183 Apr 24 13:49 hello-world.cpp +-rwxr-xr-x 1 debian debian 8944 Apr 24 13:58 hellocpp +-rw-r--r-- 1 debian debian 2356 Apr 24 16:20 helloworld.o +-rw-r--r-- 1 debian debian 3191 Apr 24 16:19 helloworld.s +-rw-r--r-- 1 debian debian 668283 Apr 24 15:42 processed.cpp +``` + +and finally obtain the executable file by: +```bash +➜ l4-CAndCpp git:(master) ✗ g++ helloworld.o -o hello-out +➜ l4-CAndCpp git:(master) ✗ ls -l +total 708 +-rw-r--r-- 1 debian debian 231 Apr 24 13:28 Readme.md +-rwxr-xr-x 1 debian debian 8144 Apr 24 13:33 hello-c +-rwxr-xr-x 1 debian debian 8944 Apr 24 16:22 hello-out +-rw-r--r-- 1 debian debian 137 Apr 24 13:33 hello-world.c +-rw-r--r-- 1 debian debian 183 Apr 24 13:49 hello-world.cpp +-rwxr-xr-x 1 debian debian 8944 Apr 24 13:58 hellocpp +-rw-r--r-- 1 debian debian 2356 Apr 24 16:20 helloworld.o +-rw-r--r-- 1 debian debian 3191 Apr 24 16:19 helloworld.s +-rw-r--r-- 1 debian debian 668283 Apr 24 15:42 processed.cpp +``` +Now you can execute it: +```bash +➜ l4-CAndCpp git:(master) ✗ ./hello-out +Hello world from beagleboard on c++!! +``` +