Difference between revisions of "Category:How to - Build helloworld"

From Gumstix User Wiki
Jump to: navigation, search
m (More detail about TMPDIR)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
==Overview==
 
==Overview==
  
What follows is a description for building C programs on a workstation using the cross-build tools of [http://wiki.openembedded.net/index.php/Main_Page OpenEmbedded], but not using the bitbake/recipe framework.
+
What follows is a description for building C programs on a workstation using the cross-build tools of Yocto, but NOT USING the bitbake/recipe framework.
  
==Setup==
+
For an alternative method USING the bitbake/recipe framework, a series of sample recipes can be found [[HelloWorld Examples | here]].
  
Follow the instructions for [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Setting-up-a-build-environment/111.html setting up a build environment] to get the cross-build tools correctly installed.
+
==Setup==
  
While you don't necessarily need to build a complete image to get the cross-tools for a C program, as a practical matter, successfully building an image is a good test that the cross-tools are correctly installed.
+
Follow the instructions for [https://github.com/gumstix/yocto-manifest/wiki setting up a build environment] to get the cross-build tools correctly installed.
  
 
The tools are built under the TMPDIR directory declared in ${OVEROTOP}/build/conf/site.conf.
 
The tools are built under the TMPDIR directory declared in ${OVEROTOP}/build/conf/site.conf.
Line 13: Line 13:
 
TMPDIR defaults to ${OVEROTOP}/tmp, but you can point it somewhere else.
 
TMPDIR defaults to ${OVEROTOP}/tmp, but you can point it somewhere else.
 
   
 
   
For instance, putting TMPDIR on a faster disk can speed your build.
 
 
 
==Makefile==
 
==Makefile==
  
Create a makefile for your project pointing to the cross-build toolchain.
+
After you have built an image, the cross-tools will be installed on your workstation.
  
Here is a simple one for helloworld.
+
You can now create a standard makefile for your project pointing to this cross-build toolchain.
 +
 
 +
Here is a simple example for helloworld.
  
 
  # Makefile for building with the OE cross tools  
 
  # Makefile for building with the OE cross tools  
Line 30: Line 30:
 
  OETMP = ${OVEROTOP}/tmp
 
  OETMP = ${OVEROTOP}/tmp
 
   
 
   
  TOOLDIR = ${OETMP}/cross/armv7a/bin
+
  # There were some OE toolchain path changes recently
   
+
   
  STAGEDIR = ${OETMP}/staging/armv7a-angstrom-linux-gnueabi/usr
+
# OE prior to around 30July2010
 +
# TOOLDIR = ${OETMP}/cross/armv7a/bin
 +
  # STAGEDIR = ${OETMP}/staging/armv7a-angstrom-linux-gnueabi/usr
 +
   
 +
# OE after 30July2010
 +
TOOLDIR = ${OETMP}/sysroots/`uname -m`-linux/usr/armv7a/bin
 +
  STAGEDIR = ${OETMP}/sysroots/armv7a-angstrom-linux-gnueabi/usr
 
   
 
   
 
  CC = ${TOOLDIR}/arm-angstrom-linux-gnueabi-gcc
 
  CC = ${TOOLDIR}/arm-angstrom-linux-gnueabi-gcc
Line 41: Line 47:
 
   
 
   
 
  INCDIR = ${STAGEDIR}/include       
 
  INCDIR = ${STAGEDIR}/include       
+
 
LIBS = -L ${LIBDIR}
+
+
 
  TARGET = helloworld
 
  TARGET = helloworld
 
   
 
   
Line 50: Line 54:
 
   
 
   
 
  ${TARGET} : $(OBJS)
 
  ${TARGET} : $(OBJS)
         ${CC} ${CFLAGS} ${OBJS} ${LIBS} -o ${TARGET}
+
         ${CC} ${CFLAGS} ${OBJS} -L ${LIBDIR} -o ${TARGET}
 
   
 
   
 
  helloworld.o: helloworld.c  
 
  helloworld.o: helloworld.c  
Line 60: Line 64:
 
==Distribute==
 
==Distribute==
  
Copy the resulting target executable to the overo.
+
After building with make, copy the resulting target executable to the overo.
 +
 
 +
Here are some alternatives.
  
 
1. If you are using [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Creating-a-bootable-microSD-card/111.html a microSD card], copy your executable to the rootfs before you unmount it in the final step.
 
1. If you are using [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Creating-a-bootable-microSD-card/111.html a microSD card], copy your executable to the rootfs before you unmount it in the final step.
Line 66: Line 72:
 
2. If you have a network connection to the overo, use scp.
 
2. If you have a network connection to the overo, use scp.
  
3. If you have a kermit console session, use the kermit SEND command.
+
==Only the Tools==
 +
 
 +
You don't need to build a complete image to get the cross-tools.
 +
 
 +
If you only want to cross compile a C program without third-party dependencies, then you can build just the gcc-cross recipe.
 +
 
 +
bitbake gcc-cross
 +
 
 +
You can use OE to selectively build additional cross-compiled libraries as needed. Look around in the OE recipes folder.
 +
 
 +
If you build a complete image, then most of the cross-build tools and libraries will get installed as as side-effect. That is probably the easiest way to setup your workstation the first time.

Latest revision as of 13:37, 1 April 2016

Overview

What follows is a description for building C programs on a workstation using the cross-build tools of Yocto, but NOT USING the bitbake/recipe framework.

For an alternative method USING the bitbake/recipe framework, a series of sample recipes can be found here.

Setup

Follow the instructions for setting up a build environment to get the cross-build tools correctly installed.

The tools are built under the TMPDIR directory declared in ${OVEROTOP}/build/conf/site.conf.

TMPDIR defaults to ${OVEROTOP}/tmp, but you can point it somewhere else.

Makefile

After you have built an image, the cross-tools will be installed on your workstation.

You can now create a standard makefile for your project pointing to this cross-build toolchain.

Here is a simple example for helloworld.

# Makefile for building with the OE cross tools 
#
# OVEROTOP is normally ${HOME}/overo-oe 
#
# OETMP is the same as TMPDIR as defined in ${OVEROTOP}/build/conf/site.conf
#

OETMP = ${OVEROTOP}/tmp

# There were some OE toolchain path changes recently
   
# OE prior to around 30July2010 
# TOOLDIR = ${OETMP}/cross/armv7a/bin
# STAGEDIR = ${OETMP}/staging/armv7a-angstrom-linux-gnueabi/usr
   
# OE after 30July2010
TOOLDIR = ${OETMP}/sysroots/`uname -m`-linux/usr/armv7a/bin
STAGEDIR = ${OETMP}/sysroots/armv7a-angstrom-linux-gnueabi/usr

CC = ${TOOLDIR}/arm-angstrom-linux-gnueabi-gcc

CFLAGS = -Wall  

LIBDIR = ${STAGEDIR}/lib

INCDIR = ${STAGEDIR}/include      
 
TARGET = helloworld

OBJS = helloworld.o 


${TARGET} : $(OBJS)
        ${CC} ${CFLAGS} ${OBJS} -L ${LIBDIR} -o ${TARGET}

helloworld.o: helloworld.c 
        ${CC} ${CFLAGS} -I ${INCDIR} -c helloworld.c  

clean:
        rm -f ${TARGET} ${OBJS} *~

Distribute

After building with make, copy the resulting target executable to the overo.

Here are some alternatives.

1. If you are using a microSD card, copy your executable to the rootfs before you unmount it in the final step.

2. If you have a network connection to the overo, use scp.

Only the Tools

You don't need to build a complete image to get the cross-tools.

If you only want to cross compile a C program without third-party dependencies, then you can build just the gcc-cross recipe.

bitbake gcc-cross

You can use OE to selectively build additional cross-compiled libraries as needed. Look around in the OE recipes folder.

If you build a complete image, then most of the cross-build tools and libraries will get installed as as side-effect. That is probably the easiest way to setup your workstation the first time.

This category currently contains no pages or media.