---
# System prepended metadata

title: embedded C newbie - Start n Try it

---

# embedded C newbie - Start n Try it

We used arm-linux-gnueabi-gcc to compile C, it will output the binary code that you can run at any ARM platform.
If you used gcc on the linux to compile the same C file, that you can get executable on x86.

Different of GCC and ARM-GCC

![](https://i.imgur.com/Czh7sHc.png)

為了後續說明，先給出一個實際案例，
實際案例如下：
#### *main.c*
![](https://i.imgur.com/g4G8ZA6.png)
#### *sub.h*
![](https://i.imgur.com/gQCExkn.png)
#### *sub.c*
![](https://i.imgur.com/tPlncaO.png)
#### *編譯結果*
![](https://i.imgur.com/oop8Pdz.png)
## Pre Treatment

為了追求方便，編譯器提供預處理命令供開發者使用，例如：
* Header 文件包含：#include
* 定義 Macro : #define
* 條件編譯：#if #else #endif
* 編譯控制：#pragma


例如上面的範例：
>![](https://i.imgur.com/c0FyKnL.png)
>利用預處理命令，在編譯過程中顯示訊息。
>![](https://i.imgur.com/QjEBMfR.png)

利用下面指令，讓main.c預處理成main.i
```
arm-linux-gnueabi-gcc -E main.c > main.i
```

簡而言之，為了方便開發，所以使用預處理命令來提升代碼可讀性，但在編譯時需要進行預處理，將含帶預處理命令的代碼還原成原汁原味的C語言。

------------------------------
## Link
### Symbol Resolution 
![](https://i.imgur.com/LYS6mkx.png)


## make the install package on linux

If we have a executable file, and we want to make it to be a installation package, run it use SHELL in any directory, we can:

*the target executable file ==helloworld==*

![](https://i.imgur.com/dvKgofU.png)

and build the diractory of the package
```mermaid
graph TB

A((helloworld))
B((DEBIAN))
C((control))
D((usr))
E((local))
F((bin))
G((helloworld))

A-->B;
B-->C;
A-->D;
D-->E;
E-->F;
F-->G;
```
the location of exectable file "helloworld" is helloworld/usr/local/bin/;and the detail of "control" file is:
```
package:helloworld
version:1.0
architecture:i386
maintainer:wit
description: deb package demo
```

and use dpkg command to package the file:
```
#dpkg -b helloworld/ <output_installation_file_name>
```
if all of step are correct, it will spwan the installation package(output_installation_file_name.deb) at the same diractory, try to use the installation package install the program:
```
#dpkg -i output_installation_file_name.deb
選取了原先未選的套件 helloworld:i386。
（讀取資料庫 ... 目前共安裝了 184942 個檔案和目錄。）
正在準備解包 helloworld_1.0_i386.deb……
解開 helloworld:i386 (1.0) 中...
設定 helloworld:i386 (1.0) ...
```
Now you can run "helloworld" at any diractory use #helloworld command:
```
~#helloworld 
Hello,World!!!

```
```