TS-7600 Cross Compiling: Difference between revisions

From embeddedTS Manuals
m (Reverted edits by Mpeters (talk) to last revision by Kris)
m (Links auto-updated for 2022 re-branding ( https://files.embeddedarm.com/ts-arm-sbc/ts-7600-linux/cross-toolchains/imx28-cross-glibc.tar.bz2 →‎ https://files.embeddedTS.com/ts-arm-sbc/ts-7600-linux/cross-toolchains/imx28-cross-glibc.tar.bz2))
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
While you can develop entirely on the board itself, if you prefer to develop from another x86 compatible Linux system we have a cross compiler available.  For this board you will want to use [ftp://ftp.embeddedarm.com/ts-arm-sbc/ts-7600-linux/cross-toolchains/imx28-cross-glibc.tar.bz2 this toolchain].  To compile your application, you only need to use the version of GCC in the cross toolchain instead of the version supplied with your distribution.  The resulting binary will be for ARM.
While it is recommend to develop entirely on the SBC itself, it is also possible to develop from an x86 compatible Linux system using a cross compiler.  For this SBC use the cross compiler located [https://files.embeddedTS.com/ts-arm-sbc/ts-7600-linux/cross-toolchains/imx28-cross-glibc.tar.bz2 here].  The resulting binary will be for ARM.


<source lang=bash>
<source lang=bash>
Line 7: Line 7:
</source>
</source>


This is one of the simplest examples.  If you want to work with a project, you will typically create a makefileYou can read more about makefiles [http://www.gnu.org/software/make/manual/make.html#Introduction here].  Another common requirement is linking to third party libraries provided by [[Debian]] on the board.  There is no exact set of steps you can take for every project, but the process will be very much the same.  Find the headers, and the librariesSometimes you have to also copy over their binaries.  In this example, I will link to sqlite from Debian (which will also work in the Ubuntu image).
This is one of the simplest examples.  For working with a larger project a Makefile will typically be usedMore information about Makefiles is available [http://www.gnu.org/software/make/manual/make.html#Introduction here].  Another common requirement is linking to third party libraries provided by [[Debian]] on the SBC.  There is no exact set of steps for every project when cross compiling, but the process will be very much the same.  Provide the cross compiler with access to the necessary headers, libraries, and source files, and install the binary on the targetThe following example will link to sqlite from Debian.


Install the sqlite library and header on the board:
Install the sqlite library and header on the SBC:
<source lang=bash>
<source lang=bash>
apt-get update && apt-get install -y libsqlite3-0 libsqlite-dev
apt-get update && apt-get install -y libsqlite3-0 libsqlite-dev
</source>
</source>


This will fetch the binaries from the internet and install them.  You can list the installed files with dpkg:
This will fetch the binaries from the internet and install them on the SBCThe installed files can then be listed with dpkg:
<source lang=bash>
<source lang=bash>
dpkg -L libsqlite3-0 libsqlite3-dev
dpkg -L libsqlite3-0 libsqlite3-dev
</source>
</source>


The interesting files from this output will be the .so files, and the .h files.  In this case you will need to copy these files to your project directory.
The needed files from this output will be the .h and .so files, they will need to be copied to the project directory on the cross-compling host.


See the example with libsqlite3 below.  This is not intended to provide any functionality, but just call functions provided by sqlite.
See the example with libsqlite3 below.  This is not intended to provide any functionality, but just call functions provided by sqlite.
Line 48: Line 48:
</source>
</source>


To build this with the external libraries I have the makefile below.  This will have to be adjusted for your toolchain path.  In this example I placed the headers in external/include and the library in external/lib.
To build this with the external libraries the makefile below can be used.  This will have to be adjusted for the proper toolchain path.  In this example, the headers are located in external/include and the library in external/lib.


<source lang=make>
<source lang=make>
Line 65: Line 65:
</source>
</source>


You can then copy this directly to the board and execute it.  There are many ways to transfer the compiled binaries to the board.  Using a network filesystem such as sshfs or NFS will be the simplest to use if you are frequently updating data, but will require more setup.  See your linux distribution's manual for more details.  The simplest network method is using ssh/sftp.  You can use winscp if from windows, or scp from linux.  Make sure you set a password from debian for root.  Otherwise the ssh server will deny connections.  From winscp, enter the ip address of the SBC, the root username, and the password you have set.  This will provide you with an explorer window you can drag files into.
The resulting binary can be copied to the target and executed.  There are many ways to transfer the compiled binaries to the board.  Using a network filesystem such as sshfs or NFS will be the simplest to use if needed frequently during development, but will require a setup.  See the host linux distribution's manual for more details.  The simplest network method is using ssh/sftp.  If running Windows, winscp can be used, or just scp in linux.  Make sure a password is set for a user account, root or otherwise, in order to properly ssh or scp files to the target.  From winscp, enter the ip address of the SBC, the root username, and the password; this will create an explorer window that can use drag-and-drop of files to copy them to the target.


For scp in linux, run:
For scp in linux, run:
<source lang=bash>
<source lang=bash>
#replace with your app name and your SBC IP address
#replace with the binary name and the SBC IP address
scp sqlitetest root@192.168.0.50:/root/
scp sqlitetest root@192.168.0.50:/root/
</source>
</source>

Latest revision as of 17:18, 17 January 2022

While it is recommend to develop entirely on the SBC itself, it is also possible to develop from an x86 compatible Linux system using a cross compiler. For this SBC use the cross compiler located here. The resulting binary will be for ARM.

[user@localhost]$ /path/to/arm-fsl-linux-gnueabi/bin/arm-linux-gcc hello.c -o hello
[user@localhost]$ file hello
hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

This is one of the simplest examples. For working with a larger project a Makefile will typically be used. More information about Makefiles is available here. Another common requirement is linking to third party libraries provided by Debian on the SBC. There is no exact set of steps for every project when cross compiling, but the process will be very much the same. Provide the cross compiler with access to the necessary headers, libraries, and source files, and install the binary on the target. The following example will link to sqlite from Debian.

Install the sqlite library and header on the SBC:

apt-get update && apt-get install -y libsqlite3-0 libsqlite-dev

This will fetch the binaries from the internet and install them on the SBC. The installed files can then be listed with dpkg:

dpkg -L libsqlite3-0 libsqlite3-dev

The needed files from this output will be the .h and .so files, they will need to be copied to the project directory on the cross-compling host.

See the example with libsqlite3 below. This is not intended to provide any functionality, but just call functions provided by sqlite.

#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"

int main(int argc, char **argv)
{
	sqlite3 *db;
	char *zErrMsg = 0;
	int rc;
	printf("opening test.db\n");
	rc = sqlite3_open("test.db", &db);
	if(rc){
		fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
		sqlite3_close(db);
		exit(1);
	}
	if(rc!=SQLITE_OK){
		fprintf(stderr, "SQL error: %s\n", zErrMsg);
	}
	printf("closing test.db\n");
	sqlite3_close(db);
	return 0;
}

To build this with the external libraries the makefile below can be used. This will have to be adjusted for the proper toolchain path. In this example, the headers are located in external/include and the library in external/lib.

CC=/opt/arm-2008q3/bin/arm-none-linux-gnueabi-gcc
CFLAGS=-c -Wall

all: sqlitetest

sqlitetest: sqlitetest.o
        $(CC) sqlitetest.o external/lib/libsqlite3.so.0 -o sqlitetest
sqlitetest.o: sqlitetest.c
        $(CC) $(CFLAGS) sqlitetest.c -Iexternal/include/

clean:  
        rm -rf *o sqlitetest.o sqlitetest

The resulting binary can be copied to the target and executed. There are many ways to transfer the compiled binaries to the board. Using a network filesystem such as sshfs or NFS will be the simplest to use if needed frequently during development, but will require a setup. See the host linux distribution's manual for more details. The simplest network method is using ssh/sftp. If running Windows, winscp can be used, or just scp in linux. Make sure a password is set for a user account, root or otherwise, in order to properly ssh or scp files to the target. From winscp, enter the ip address of the SBC, the root username, and the password; this will create an explorer window that can use drag-and-drop of files to copy them to the target.

For scp in linux, run:

#replace with the binary name and the SBC IP address
scp sqlitetest root@192.168.0.50:/root/

After transferring the file to the board, execute it:

ts:~# ./sqlitetest 
opening test.db
closing test.db