Application Development
Cross-Compiling Applications
Running make cross-compiles your applications
according to the environment settings. By installing a Cross-Compilation
Toolchain for your target, the environment variables are set up for
cross-compilation. For more details, see .
Once the cross-compilation environment is set up, you can make your
applications as usual and get them compiled for your target. Below you see
how to cross-compile from the command line. If Eclipse is installed, you
can also cross-compile your code from the Eclipse IDE. For more details,
see .
Create a Makefile for your application. Example of a simple
Makefile and application:
helloworld:helloworld.o
$(CC) -o helloworld helloworld.o
clean:
rm -f *.o helloworld
#include <stdio.h>
int main(void) {
printf("Hello World\n");
return 0;
}
Run make to cross-compile your application
according to the environment set up:
$ make
If the build fails, check if the GNU Make workaround solves
your problem.
Copy the helloworld program to your target
and run it:
# ./helloworld
Hello World
Cross-Compiling Kernel modules
Running make cross-compiles your kernel modules
according to the environment settings. By installing a Cross-Compilation
Toolchain for your target, the environment variables are set up for
cross-compilation. For more details, see .
Before cross-compiling kernel modules, you need to make sure the
installed toolchain includes the kernel source tree, which should be
available at:
<sdkdir>/sysroots/<targetarch>-enea-linux/usr/src/kernel.
If the kernel source tree is not included in the toolchain, you need to
add the kernel-dev package into the image recipe enea-image-<name>
and build the toolchain again.
Once the cross-compilation environment is set up, you can make your
kernel modules as usual and get them compiled for your target. Below you
see how to cross-compile a kernel module.
Create a Makefile for the kernel module. Example of a simple
Makefile and kernel module:
obj-m := hello.o
PWD := $(shell pwd)
KERNEL_SRC := <full path to kernel source tree>
all: scripts
$(MAKE) -C $(KERNEL_SRC) M=$(PWD) LDFLAGS="" modules
scripts:
$(MAKE) -C $(KERNEL_SRC) scripts
clean:
$(MAKE) -C $(KERNEL_SRC) M=$(PWD) LDFLAGS="" clean
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello, world\n");
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye, world\n");
}
module_init(hello_start);
module_exit(hello_end);
MODULE_LICENSE("GPL");
Run make to cross-compile your kernel module
according to the environment set up:
$ make
Copy the kernel module hello.ko to your
target and install/remove it:
# insmod hello.ko
# rmmod hello.ko
# dmesg
[...] Loading hello module...
[...] Hello, world
[...] Goodbye, world