1 How to build C sample codes {#build}
3 @brief Tutorial to build the C sample code and introduction to Linux toolchain.
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.
11 The following compiler tools are provided:
15 ar | Manage archives (static libraries)
17 c++, g++ | C++ compiler
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)
33 The native compiler, ioThinx library and necessary packages are already installed on ioThinx 4530 series devices.
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.
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.
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.
44 user@Linux:~$ unzip ioThinx_4530_toolchain_V1.0_Build19030819.zip
45 user@Linux:~$ sudo ./ioThinx_4530_toolchain_V1.0_Build19030819.sh
48 You can check the toolchain version using the following command:
50 user@Linux:~$ /usr/local/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -v
53 You can now start compiling programs using this toolchain.
57 # To build the C sample code
59 ## Using native toolchain
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:
64 user@Linux:~$ scp sample.tar.gz moxa@192.168.127.254:~
66 2. Extract the sample code
68 moxa@Moxa:~$ tar zxvf sample.tar.gz
70 3. Build all sample code
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
76 (You can also build the sample code individually)
78 moxa@Moxa:~/sample/iothinx/c$ cd api/io
79 moxa@Moxa:~/sample/iothinx/c/api/io$ make di
83 moxa@Moxa:~/sample/iothinx/c/api/io$ sudo ./di -h
86 ## Using cross toolchain
88 1. Copy sample.tar.gz contained in the programing guide to your PC
89 2. Extract the sample code
91 user@Linux:~$ tar zxvf sample.tar.gz
93 3. Build all sample code
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
99 (You can also build the sample code individually)
101 user@Linux:~/sample/iothinx/c$ cd api/io
102 user@Linux:~/sample/iothinx/c/api/io$ make di
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:
107 user@Linux:~/sample/iothinx/c/api/io$ scp di moxa@192.168.127.254:~
109 5. Run the program on ioThinx
111 moxa@Moxa:~$ sudo ./di -h