Cross compiling voor Synology
In deze post gaan we een C programma compileren op Ubuntu waarvan de output geschikt is om op je Synology te draaien.
Uit de DSM developer guide:
To compile an application for the Synology DiskStation, a compiler that runs on Linux PC is required in order to generate an executable file for the Synology DiskStation. This compiling procedure is called "cross compiling" and the set of compiling tools (compiler, linker, etc.) used to compile the application is called a "tool chain".
We maken gebruik van Ubuntu 14.04.3 LTS 64-bit te downloaden van http://www.ubuntu.com/download/desktop.
Installeer Ubuntu met default instellingen. Je kunt Ubuntu fysiek of virtueel installeren. Of als live cd/usb. Dat maakt voor dit niet zoveel uit.
Installeer hierna de volgende packages:
Dit is niet nodig als je voor Ubuntu 32-bit kiest.
Download de juiste tool chain voor je Synology van http://sourceforge.net/projects/dsgpl/files/.
Controleer op de Synology welk model je hebt.
Ik draai DSM 5.2 en heb een "synology_alpine_ds715" en kies dus de volgende tool chain:
Pak de toolchain uit en zet deze in /usr/local.
Hierna zijn de volgende tools beschikbaar:
(de output en paden kunnen/zullen afwijken per Synology model)
De volgende stap is het compileren van een testprogramma bijvoorbeeld:
C:
Compileer als volgt:
We zien dat er een executable voor ARM wordt aangemaakt die (uiteraard) niet kan worden uitgevoerd op deze Ubuntu installatie.
Kopieer de executable naar de Synology en probeer opnieuw.
Op deze manier kun je dus programma's compileren zonder dat je hiervoor iets op de Synology hoeft te installeren en/of uit te voeren.
Later meer over make/install en Synology packages...
N.B.
Als je via een terminal emulator zoals PuTTY verbinding wil maken dan kun je op Ubuntu de volgende package installeren:
Kopieren naar de Synology kan eenvoudig door gebruik te maken van scp.
Uit de DSM developer guide:
To compile an application for the Synology DiskStation, a compiler that runs on Linux PC is required in order to generate an executable file for the Synology DiskStation. This compiling procedure is called "cross compiling" and the set of compiling tools (compiler, linker, etc.) used to compile the application is called a "tool chain".
We maken gebruik van Ubuntu 14.04.3 LTS 64-bit te downloaden van http://www.ubuntu.com/download/desktop.
Installeer Ubuntu met default instellingen. Je kunt Ubuntu fysiek of virtueel installeren. Of als live cd/usb. Dat maakt voor dit niet zoveel uit.
Installeer hierna de volgende packages:
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6
Dit is niet nodig als je voor Ubuntu 32-bit kiest.
Download de juiste tool chain voor je Synology van http://sourceforge.net/projects/dsgpl/files/.
Controleer op de Synology welk model je hebt.
DS715> uname -a Linux DS715 3.2.40 #5592 SMP Wed Jul 29 14:39:17 CST 2015 armv7l GNU/Linux synology_alpine_ds715 DS715>
Ik draai DSM 5.2 en heb een "synology_alpine_ds715" en kies dus de volgende tool chain:
- DSM 5.2 Tool Chains
- Annapurna Alpine Linux 3.2.40
- alpine-gcc472_glibc215_alpine-GPL.txz
sudo su -
Pak de toolchain uit en zet deze in /usr/local.
tar -Jxf alpine-gcc472_glibc215_alpine-GPL.txz -C /usr/local
Hierna zijn de volgende tools beschikbaar:
root@ubuntu:~# /usr/local/arm-linux-gnueabihf/bin/arm-linux-gnueabihf- arm-linux-gnueabihf-addr2line arm-linux-gnueabihf-gprof arm-linux-gnueabihf-ar arm-linux-gnueabihf-ld arm-linux-gnueabihf-as arm-linux-gnueabihf-ld.bfd arm-linux-gnueabihf-c++ arm-linux-gnueabihf-ldd arm-linux-gnueabihf-c++filt arm-linux-gnueabihf-ld.gold arm-linux-gnueabihf-cpp arm-linux-gnueabihf-nm arm-linux-gnueabihf-elfedit arm-linux-gnueabihf-objcopy arm-linux-gnueabihf-g++ arm-linux-gnueabihf-objdump arm-linux-gnueabihf-gcc arm-linux-gnueabihf-pkg-config arm-linux-gnueabihf-gcc-4.7.2 arm-linux-gnueabihf-pkg-config-real arm-linux-gnueabihf-gcc-ar arm-linux-gnueabihf-ranlib arm-linux-gnueabihf-gcc-nm arm-linux-gnueabihf-readelf arm-linux-gnueabihf-gcc-ranlib arm-linux-gnueabihf-size arm-linux-gnueabihf-gcov arm-linux-gnueabihf-strings arm-linux-gnueabihf-gdb arm-linux-gnueabihf-strip arm-linux-gnueabihf-gfortran root@ubuntu:~#
(de output en paden kunnen/zullen afwijken per Synology model)
De volgende stap is het compileren van een testprogramma bijvoorbeeld:
C:
1
2
3
4
5
| #include <stdio.h> main() { printf("Hello World"); } |
Compileer als volgt:
root@ubuntu:~# /usr/local/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc helloworld.c -o helloworld root@ubuntu:~#
We zien dat er een executable voor ARM wordt aangemaakt die (uiteraard) niet kan worden uitgevoerd op deze Ubuntu installatie.
root@ubuntu:~# file helloworld helloworld: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31, BuildID[sha1]=7369bffdeabe1e55d9e113baf44aefd042e2d8c5, not stripped root@ubuntu:~# ./helloworld -su: ./helloworld: cannot execute binary file: Exec format error root@ubuntu:~#
Kopieer de executable naar de Synology en probeer opnieuw.
DS715> ./helloworld Hello World DS715>
Op deze manier kun je dus programma's compileren zonder dat je hiervoor iets op de Synology hoeft te installeren en/of uit te voeren.
Later meer over make/install en Synology packages...
N.B.
Als je via een terminal emulator zoals PuTTY verbinding wil maken dan kun je op Ubuntu de volgende package installeren:
sudo apt-get install openssh-server
Kopieren naar de Synology kan eenvoudig door gebruik te maken van scp.
root@ubuntu:~# scp helloworld admin@DS715:/tmp admin@DS715's password: helloworld 100% 5351 5.2KB/s 00:00 root@ubuntu:~#