- Main
- Tutorials
- Library
- Samples

- File List
- Globals

tutorial/iothinx/c/build.md
Go to the documentation of this file.
1 How to build C sample codes {#build}
2 ----
3 @brief Tutorial to build the C sample code and introduction to Linux toolchain.
4
5 # Linux Toolchain
6
7 ## Introduction
8
9 Linux toolchain contains the necessary libraries and compilers for developing your programs. ioThinx 4530 Series support both native and cross compiling of code. Native compiling is more straightforward since all the coding and compiling can be done directly on the device, but Arm architecture is less powerful, the compiling speed is slower. On the other hand, cross compiling can be done on any Linux machine using a toolchain, and the compiling speed is much faster.
10
11 The following compiler tools are provided:
12
13 Tool | Usage
14 -------- | -----
15 ar | Manage archives (static libraries)
16 as | Assembler
17 c++, g++ | C++ compiler
18 cpp | C preprocessor
19 gcc | C compiler
20 gdb | Debugger
21 ld | Linker
22 nm | Lists symbols from object files
23 objcopy | Copies and translates object files
24 objdump | Displays information about object files
25 ranlib | Generates indexes to archives (static libraries)
26 readelf | Displays information about ELF files
27 size | Lists object file section sizes
28 strings | Prints strings of printable characters from files (usually object files)
29 strip | Removes symbols and sections from object files (usually debugging information)
30
31 ## Native Compilation
32
33 The native compiler, ioThinx library and necessary packages are already installed on ioThinx 4530 series devices.
34
35 ## Cross Compilation
36
37 To ensure that an application will be able to run correctly when installed on ioThinx 4530 series, you must compile the application and link it to the same libraries that will be present on ioThinx 4530 series. This is particularly true when the Arm-based Cortex processor architecture differs from the CISC x86 processor architecture of the host system, but it is also true if the processor architecture is the same.
38
39 The host toolchain that comes with the ioThinx 4530 series devices contains a suite of cross compilers, ioThinx library and other tools, as well as the libraries and headers that are necessary to compile applications for the ioThinx 4530 series devices. The host environment must be running Linux to install the Moxa GNU Tool Chain.
40
41 The toolchain will need about 1GB of hard disk space on your PC. To install the toolchain, download the toolchain file from Moxa’s website. After you untar the package, run the following script to install the toolchain.
42
43 ```
44 user@Linux:~$ unzip ioThinx_4530_toolchain_V1.0_Build19030819.zip
45 user@Linux:~$ sudo ./ioThinx_4530_toolchain_V1.0_Build19030819.sh
46 ```
47
48 You can check the toolchain version using the following command:
49 ```
50 user@Linux:~$ /usr/local/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -v
51 ```
52
53 You can now start compiling programs using this toolchain.
54
55 \n
56
57 # To build the C sample code
58
59 ## Using native toolchain
60
61 1. Copy sample.tar.gz contained in the programing guide from your PC to ioThinx:\n
62 For example, if the IP address of the ioThinx is "192.168.127.254", use the following command:
63 ```
64 user@Linux:~$ scp sample.tar.gz moxa@192.168.127.254:~
65 ```
66 2. Extract the sample code
67 ```
68 moxa@Moxa:~$ tar zxvf sample.tar.gz
69 ```
70 3. Build all sample code
71 ```
72 moxa@Moxa:~$ cd sample/iothinx/c
73 moxa@Moxa:~/sample/iothinx/c$ ln -s toolchain-config-native config.mk
74 moxa@Moxa:~/sample/iothinx/c$ make
75 ```
76 (You can also build the sample code individually)
77 ```
78 moxa@Moxa:~/sample/iothinx/c$ cd api/io
79 moxa@Moxa:~/sample/iothinx/c/api/io$ make di
80 ```
81 4. Run the program
82 ```
83 moxa@Moxa:~/sample/iothinx/c/api/io$ sudo ./di -h
84 ```
85
86 ## Using cross toolchain
87
88 1. Copy sample.tar.gz contained in the programing guide to your PC
89 2. Extract the sample code
90 ```
91 user@Linux:~$ tar zxvf sample.tar.gz
92 ```
93 3. Build all sample code
94 ```
95 user@Linux:~$ cd sample/iothinx/c
96 user@Linux:~/sample/iothinx/c$ ln -s toolchain-config-cross config.mk
97 user@Linux:~/sample/iothinx/c$ make
98 ```
99 (You can also build the sample code individually)
100 ```
101 user@Linux:~/sample/iothinx/c$ cd api/io
102 user@Linux:~/sample/iothinx/c/api/io$ make di
103 ```
104 4. Copy the sample program to ioThinx:\n
105 For example, if the IP address of the ioThinx is "192.168.127.254", use the following command:
106 ```
107 user@Linux:~/sample/iothinx/c/api/io$ scp di moxa@192.168.127.254:~
108 ```
109 5. Run the program on ioThinx
110 ```
111 moxa@Moxa:~$ sudo ./di -h
112 ```