Calling All Android Fans!

We came across this rather neat app recently:
https://market.android.com/details?id=moduleWorks.STLView

It’s a handy tool to view STL files either on the move, or in a really intuitive way: if you press the globe icon on the left hand side of the screen, the app uses the tablet’s gyro / accelerometer to orbit round the STL as you rotate the tablet.

If you work with STL files, and have an Android tablet this is well worth a try!

STLView comes from ModuleWorks: http://www.moduleworks.com/index.asp
Yoda came from Thingiverse: http://www.thingiverse.com/thing:10752

QuickForge – Rapid 3D Printing

When we say instant quote…

… We really do mean instant!

Our quotation process is unique, and it really is extremely quick.

Here’s how it works:
Hit the “Quote Me” button; enter 4 key facts about your model: Its enclosing Length, Width, Height and the colour you’d like it to be. Hit continue, and the quote will be on your screen faster than you can say “fused deposition modelling”! *

 

*Internet connection speed permitting, naturally… if you’re out in the styx, you might need to say “fused deposition modelling from a stereolithography file”, but you get the idea.

QuickForge – Rapid 3D Printing

Cross-Compiling in Code::Blocks and Running Your Program on the Target Device

Previously in this blog series, I discussed a few options for cross-compilers and IDEs compatible with Windows (and in fact Linux and Mac as well). I demonstrated how to build the Boost library and how to generate a cross-compile Code::Blocks project for Wt using CMake.

I’m now going to cover compiling of the hello.wt build target that is included as one of many in the generated WT Code::Blocks project. A build target is typically a variant of the same program i.e. targeted for a different platform, targeted for debug etc. but generally the program itself is functionally similar. In this instance, CMake has provided us with various different sample programs that are not functionally similar, each configured as their own build target. This is fine for our purposes but if you wished you can create a separate, stand-alone project from these build targets; instructions for this can be found in Code::Block’s Help menu.

I have chosen to focus on hello.wt as it’s the perfect template for creating my own program. I can either simply modify hello.C or I could create a new project with the Hello.wt settings as a guideline. Hello.wt is programmed to demonstrate how to:

  • Start a web-server.
  • Create a new session when a user connects.
  • Create widgets and add them to the widget tree (a hierarchy representing a webpage).
  • React to events using the signal/slot mechanism.
  • Read user input and update widgets accordingly.

Simply put, it sets up a web address a user can connect to, displays a message asking for the user’s name and updates the widgets to display that name back to the user, all without refreshing the page, which is where the signal/slot mechanism comes in handy! Essentially all the basic building blocks needed to expand from for my own program. For more information on actually building an application, you can look to the Wt website where there are examples, guides, a wiki, full documentation and an active user forum.

Building hello.wt isn’t all that difficult, but first I must add the Code Sourcery cross-compiler details to Code::Blocks. This is a one time occurrence and I can reuse these settings in future projects. To add a new compiler option within Code::Blocks I must navigate to Settings > Compiler and debugger settings. By default I’m taken to the Global compiler settings page. Oddly I can only create a new compiler entry by copying an existing entry; thankfully though, there’s already an option GNU ARM GCC Compiler that’s the perfect template. I will simply add my details to this compiler option but alternatively if I had several ARM compilers, I could create a copy of this for each one.

Under Toolchain executables I need to inform Code::Blocks of the names and locations of the various programs used to build a project, here’s the list of the settings I used:

  • Compiler’s installation directory - C:Sourcery_G++_Lite
  • C compiler - arm-none-linux-gnueabi-gcc.exe
  • C++ compiler - arm-none-linux-gnueabi-g++.exe
  • Linker for dynamic libs – arm-none-linux-gnueabi-g++.exe
  • Linker for static libs - arm-none-linux-gnueabi-ar.exe
  • Debugger - arm-none-linux-gnueabi-gdb.exe
  • Resource compiler – Leave empty
  • Make program – cs-make.exe

Under Search directories > Compiler I added the location C:Sourcery_G++_Litearm-none-linux-gnueabiinclude to point to the source code of the tool-chain.

Under Search directories > Linker I added the location C:Sourcery_G++_Litearm-none-linux-gnueabilibc to point to the libraries of the tool-chain.

Depending on the architecture and the optimisation you’re looking for you may also need/wish to configure settings on the Compiler Flags tab. You can find out what settings you should be using by reading both the Code Sourcery manuals and reading your embedded device’s documentation.

Now that all that’s done, I have to set hello.wt as my active build target. This can be done from one of the tool-bars or from the menu it’s Build > Select target. Finally, I must inform hello.wt that I wish it to use my ARM compiler that I configured previously. I can either do this by right-clicking on the WT project and selecting Build options… or from the menu it’s Project > Build options… . From here I can select my compiler from the drop-down list and that’s a wrap! I can now build my project, though the first time as large sections of Wt are also being compiled this can take around 8-12 minutes. The executable file hello.wt will be generated, it’s worth noting that executables on Linux do not all have a single extension like exe in Windows.

There are three approaches to running a compiled program on the target device. The first requires that I include the Code Sourcery tool-chain when building my root file-system. This is a step usually partaken when creating your own distribution/flavour of Linux, as such I will not be discussing the approach in this blog series. If you find yourself lucky enough that Code Sourcery is part of your distribution’s root file-system, then you can run your program as if it had been compiled natively right on the target device and you would have no need to read any further.

The remaining two approaches require that I copy the Code Sourcery tool-chain onto my target device which, alas is not quite as easy as copy and paste. The approach I take assumes the target device has a network connection. I can either download the following archive directly from the internet or first to my PC and host a local web-server, which I highly recommend as it’s a simple approach to transferring files that avoids the spotty and varied results of configuring a shared network drive and saves the tedious to and fro action of transferring by USB stick. Almost all GNU Linux distributions come with the software/command wget pre-installed that can be used to fetch files over HTTP, HTTPS or FTP.

Using this command I download the file IA32 GNU/Linux TAR from the Code Sourcery website (or my local web-server). The file is found on the same page I downloaded my Windows installer from. This file contains the standard x86 Linux copy of the Code Sourcery cross-compiler and is not meat for use on the ARM target device, however inside this file is the folder arm-none-linux-gnueabi/libc which contains the ARM edition of the compiler and tool-chain. This folder is also supplied with the Windows edition of the tool-chain but due to the differences in file-systems, important symbolic links (short-cuts) and file permissions are lost in translation.

I proceed by extracting the TAR file and copying libc to the root of my file system, though in practise the location or name isn’t important. It’s now safe to delete the TAR and the remaining extracted files, in fact, if I do not intend to perform any compiling with Code Sourcery directly on the device, it’s safe to also delete the libc/usr/include sub-directory and any .so or .a files. Here’s a quick example of my command line operations:

  • wget https://sourcery.mentor.com/sgpp/lite/arm/portal/package8739/public/arm-none-linux-gnueabi/arm-2011.03-41-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
    • Fetches the IA32 GNU/Linux TAR file from the internet.
  • tar -xvf arm* arm-none-linux-gnueabi/libc
    • Extracts the correct ‘libc’ folder to the current directory. Option ‘x’ is to extract, ‘v’ to ask for feedback of the extraction process, ‘f’ to allow us to specify the file-name. ‘arm*’ says to extract all files beginning with the text ‘arm’, this saves me typing out the really long file-name, just make sure you have no other files beginning with ‘arm’ in the same directory!
  • rm -vr ./libc/usr/include
    • Remove unwanted files and folders. Option ‘v’ is the same as with tar and will provide feedback of the process, ‘r’ is recursive, meaning to repeat the removal process in all subdirectories. Be VERY careful with this command, worst case scenario you delete everything!
  • find ./libc/ -iname “*.so” -exec rm ‘{}’ ‘;’
  • find ./libc/ -iname “*.a” -exec rm ‘{}’ ‘;’
    • Remove all .so and .a files. As we do not know their names and due to limitations of the rm command, we use the find command instead.
  • rm -vr ./libc/armv4t
  • rm -vr ./libc/thumb2
    • Remove more unwanted folders, these are in fact alternate tool-chains for different versions of ARM processors. Check the documentation to know if you should be using one of these instead of libc.
  • sudo mv ./libc /
    • Move libc to the the root directory, ‘sudo’ is used to grant admin access to the root directory and will prompt you for your admin password.

This may seem a little complicated but it’s essentially 8 brief command-line commands to download, extract, prepare and place the tool-chain onto the target device ready for use (3 if you don’t mind a little bloat from the un-deleted files and folders). I’m now ready to continue exploring the remaining two approaches to running my program on the target system.

The second approach is to dynamically link a compiled program to the tool-chain at runtime. This is the simplest and quickest approach for me to test out my hello.wt program. However I should avoid this option unless I have no way of knowing the location of the tool-chain on the target device prior to building my program. I can not debug with this method and I must always type the following to run my programs, which is cumbersome in the long run, here’s an example command to run hello.wt:

  • /libc/lib/ld-linux.so.3 –library-path /libc/lib:/libc/usr/lib /path/to/hellowt/hello.wt –http-port 10000 –http-addr 0.0.0.0 –docroot .
    • This command uses ld-linux.so.3 to link hello.wt to the Code Sourcery libraries. The commands after hello.wt will cause the program to load a web-server on the default interface on port 10,000. To test if this has worked, from a web-browser on the device’s network, type http://my.device.ip:10000/

I took this opportunity to test my program and it worked just as expected, which is brilliant as it has been a rather long road! I performed the above steps by downloading hello.wt with wget and running the following command, used to set file permissions, to make the program executable: chmod 100 hello.wt. For security reasons, if you haven’t read up on chmod, I strongly recommend doing so. If you have decided to follow my footsteps and receive an error at this stage, I recommend back-tracing your own footsteps before proceeding, feel free to ask for advise in the comments section of this post.

The third approach is the method I will be looking to use long-term for this project. It enables me to specify the locations of the Code Sourcery libraries at compile-time so that I can avoid the long command of approach two and the difficult set-up of approach one whilst still being able to debug my program. To set this up I would typically jump back into Code::Blocks and navigate back to my Compiler and debug settings > Linker settings. However, as Wt was built with CMake, the CMake project files handle the entire build process and bypass Code::Blocks settings. In a rather quick and rough manner I navigate to MyWtBuildDirectoryexampleshelloCMakeFileshello.wt.dir and open in WordPad the file flags.make. Here is where I can specify my custom compiler and linker flags. I add the following to the end of the CXX_FLAGS line:

-Wl,-rpath=/libc/lib:/libc/usr/lib -Wl,–dynamic-linker=/libc/lib/ld-linux.so.3

Essentially I’ve added the same command from approach two, only it’s now hard-wired into the program. I can now re-build my program from Code::Blocks, copy over the new hello.wt, set the chmod permissions and run it with a simple:

./hello.wt

I think I’ll take a little break here! Look forward to a post on remote debugging next time.

Alistair
QuickForge – Rapid 3D Printing

A small side-note on CodeSourcery and Code::Blocks binary choices

Following up on reader responses, I wished to take a moment and clarify some of the exact binary choices I made regarding the CodeSourcery toolchain and the Code::Blocks binary in my post, Exploration of Cross-Compiling on Windows for ARM Linux Distributions; I’m doing so with a separate post in order to allow the blog series to remain more of flexible guide than an exact tutorial.

When you reach the CodeSourcery website and subsequently the Sourcery CodeBench Lite Edition for ARM download page, you’ll be presented firstly with a choice of Target OS’. The tool-chain to download is GNU/Linux. UClinux and Symbian are different operating systems and EABI is designed to produce standalone programs that run without an operating system.

Code::Blocks offers the choice of a standard set-up and a set-up that comes with the MinGW compiler and tool-chain. MinGW is designed as a GNU alternative to Microsoft’s own compiler MSVC. As the compiler is GNU, porting of programs can become a little easier. Either way having this compiler does not affect your ability to use MSVC or any cross-compilers and so either binary choice for Code:Blocks is perfectly valid for this blog series.

Alistair
QuickForge – Rapid 3D Printing

Exploration of Cross-Compiling on Windows for ARM Linux Distributions

Hey guys, we have an upcoming TOP SECRET project that’s going to involve development work with a small ARM CPU based ‘System on a Board’ running Linux. During this process I’m going to document some of our experiences, trials, tribulations and successes so that others can learn from our mistakes and share in our victories.

Now I’m typically a Windows developer so building programs for Linux is fairly new to me. I also have the difficulty that there’s not enough on-board memory to develop software on the device itself; it also requires a special compiler for the ARM instruction set.

My only solution is to Cross-Compile, which is where I build my program on a different kind of system, but target the system that it’s going to wind up on. For ARM there are several free cross compiler solutions out there, though only a few support Windows and even less are frequently maintained. Some examples would be GNUARM (last updated 2006), YAGARTO, DevKitPro ARM and CodeSourcery G++ Lite.

Another piece of the puzzle is an IDE, notepad and command-line just don’t cut it when working on complex projects, at least not for a windows developer! Two good free IDEs spring to mind, both are powerful, cross-platform and support cross-compiling. The First is the Eclipse IDE, it’s highly user friendly, built in Java and is used as the basis of some commercial cross-compiling solutions, however from my experience a little unstable and resource hungry. A good alternative is the Code::Blocks IDE, it’s a little basic in comparison to Eclipse (though has a good plug-in system to expand functionality) but is built in C++ and as such provides great performance with a much smaller resource footprint, from experience I can say it’s also very stable.

For this project I’ve decided to use the Code::Blocks IDE along with CodeSourcery G++ Lite as my cross-compiler and toolset; it had a few advantages over alternatives: it’s a free aspect of a commercial solution, and so well maintained and optimised, does not require Cygwin and comes with the correct command-line tools ready for use by Code::Blocks. I’ll take a moment to recommend that anyone following in my footsteps installs their cross-compiler to a directory without any spaces in the name, as some libraries have trouble with this.

Now that I’m set-up, my first challenge is to familiarise myself with Code::Blocks, the library structure and system used by Linux and how to cross-compile a project with library prerequisites. I’m first going to take a look at compiling some prerequisite libraries. I’ll start with Boost, a great multi-platform library providing all the functionality that people felt was left out of the C++ Standard Library collection, in fact it’s so useful, it’s now slowly being integrated into the Standard. After extracting the latest packed release, you’ll find in the root that Boost has a file called bootstrap.bat, usefully this will generate boost’s own installer (Jam) for Windows; this does require the Microsoft Visual C++ (msvc) compiler and so make sure you have a version of Visual Studio installed, if you don’t own a copy you can download the free express edition. After running this file, to cross-compile, I need to configure project-config.jam, replacing the line using mscv ; with my cross-compiler settings using gcc : arm : “C:/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-g++.exe” ; I can now run the following command from within the Boost root directory in the command-line bjam install –prefix=myInstallLoation toolset=gcc-arm target-os=linux, optionally you may wish include the following compiler arguments within project-config.jam that can be ideal for embedded systems with limited memory:

  • -fvisibility=hidden -fvisibility-inlines-hidden – Decreases library size by avoiding exporting of unneeded symbols.
  • -ffunction-sections -fdata-sections – A more intensive but memory friendly garbage collection.

e.g. using gcc : arm : “C:/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-g++.exe” : <compileflags>-fvisibility=hidden ;

If your version of Boost won’t compile the thread library, it’s likely because it thinks you’re building for Windows, passing threadapi=pthread as a command-line argument will force the correct library to be built.

It’s particularly important to include install –prefix=myInstallLoation as opposed to simply compiling Boost, as this will lay out the correct Boost directory structure for easily including the library into future projects.

It can take a while but after this the boost library will be cross-compiled.

Linux libraries have different extensions to Windows:

  • .a – Static Library (archive) equivalent of .lib
  • .so – Dynamic Library (shared object) equivalent of .dll
Where possible I’m going to use static libraries as they’re memory friendly for individual programs; if you expect to be using the same library in multiple programs at the same time, dynamic libraries may be for you.

It’s worth noting that many libraries now come with support for the cross-platform CMake build system and so I made sure to install the latest copy. Usefully, it’s now possible to generate a Code::Blocks or Eclipse project with CMake.

To create a Code::Blocks project with CMake, open up CMake, complete the boxes Where is the source code and Where to build the binaries. The source-code field should point to the first folder in the library project with a cmake file present and you may enter any directory of your choice for the binaries, it’ll be created if it doesn’t exist.

Proceed by clicking Generate. Select CodeBlocks – Unix Makefiles as your generator and Specify options for cross-compiling.

For Operating System enter Linux, version enter 1. For Compilers, find the location of your CodeSourcery bin folder, for me it was C:/Sourcery_G++_Lite/bin/. For C select arm-none-linux-gnueabi-gcc.exe and for C++ select arm-none-linux-gnueabi-g++.exe. Finally, for Target Root, find the location of your CodeSourcery libc folder, for me it was C:/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc; CMake will use this directory to search for target libraries, you may add other directories at any time by space-separating them.

A quick note, if you receive the error “…unable to find a build program…” at any stage when generating a CMake project. Head to your CodeSourcery bin folder, make a copy of cs-make.exe and rename it to make.exe.

Using the above instructions, I’m going to generate a Code::Blocks project for Wt (Witty – A C++ Web Tool-kit). Wt is a high-performance, highly secure tool for creating responsive web 2.0 applications, it also comes with its own web-server. Great for an embedded system with a network port!

When first generating a project in CMake, it will likely produce errors and highlight values in red. Typically these are requests for the location of various prerequisite libraries. How convenient it is then that Wt requires the Boost library that I just compiled! CMake is capable of automatically detecting the boost library with an entry in BOOST_PREFIX, however I need to give it a helping hand when cross-compiling. In BOOST_PREFIX, I enter the boost install directory I specified earlier along with some more of the generated file structure, C:/myInstallLocation/Boost/include/boost-1_47, this will of course change if using a different version of Boost. With this CMake is able to detect my Boost header files but not my library files; this is because it is expecting library files containing the phrase win32 instead of gcc, I can correct this by clicking + Add Entry in CMake and adding an entry with Name Boost_COMPILER, Type String and Value -gcc to force the CMake Boost search script to look for the correct libraries. With that it should be all over but CMake will still fail to find the boost_thread library, again, this is because it is expecting a different Windows related name, I can force CMake to search for the pthread version of boost_thread by adding a further entry of Name Boost_THREADAPI, Type String and Value pthread. Boost will now be detected successfully.

A quick note, in CMake 2.8.6 or older, there is a bug in the Boost search script that will prevent discovery of boost_thread. To fix this, locate the file FindBoost.cmake within the CMakeInstallation/share/cmake-2.8/Modules, this location will vary depending on the version of CMake. Inside this file, search for the line string(REPLACE “thread” “thread_${Boost_THREADAPI}” _threadapi_libnames ${_orig_libnames}) and replace it with string(REPLACE “thread” “thread_${Boost_THREADAPI}” _threadapi_libnames “${_orig_libnames}”). It’s worth noting that from the Modules directory, it is possible to view other automated CMake search scripts along with the custom entries that you can specify for each script.

In the same way I could provide options to memory optimise boost, I can provide options for Wt; a full list of options and advice can be found here: http://redmine.emweb.be/projects/wt/wiki/Wt_embedded. Once everything’s configured, hit Generate and your project files will be created. To open the new project, load up Code::Blocks and from the File menu, select Open. Navigate to your Wt build directory, searching for a .cbp file and you’re off!

I hope that my experiences will prove useful to the potential Windows cross-compilers out there. I’ll be making a separate post on configuring the cross-compiler and building in Code::Blocks.

Alistair
QuickForge – Rapid 3D Printing

Next Post: Cross-Compiling in Code::Blocks and Running Your Program on the Target Device

Side Note: A small side-note on CodeSourcery and Code::Blocks binary choices

Welcome to the QuickForge Blog

Welcome Reader!

Here at QuickForge we are absolutely fascinated by the vast possibilities of 3D Printing and everything loosely related! If you’re reading this blog, we suspect you may share some of that same affinity.

This is where we will be sharing our thoughts, our findings and some hints and tips on 3D printing and related technology. We’ll also take every opportunity to showcase some of the interesting bits we’ve helped people to create and to demonstrate the wondrous uses of 3D printing.

Ladies and Gentlemen,
Please enjoy the ride!