In previous chapter we used Eclipse for Embedded linux development and remote debugging of simple application for embedded linux. Now we are getting one step closer to OpenWrt – we will use Eclipse for development and remote debugging of application represented as OpenWrt package (Makefile based application, in fact). But this article might be useful for any other Embedded linux build system.
Hello World package
In previous chapter we created simple Hello World application containing just one single C source file:
with following content:
Now we will transform it to OpenWrt package:
open it with any text editor and enter:
There is pretty simple Makefile to build simple application.
Then we need to create package’s Makefile:
Again open it with editor and enter:
Looks completely different from typical Makefile’s content. There is package manifest file describing steps to be passed before, during and after compilation.
So as a result you should get following structure in package/helloworld folder:
Time to compile it. Go back to the root and start package building process:
The output generated by V=s helps you to understand build process flow.
As a result you may find following:
there is content of src folder we created before (helloworld.c and Makefile) and few resulted output files including application executable. You can open helloworld.c and/or Makefile and make sure that there are files we created before. Switch back to package manifest file and find following definition:
that responsible for such source code copying. There is one of peculiarity of OpenWrt – building of sources happens in separate folder.
Because of that it looks quite difficult use initial sources (./package/helloworld) folder for experiments with Eclipse. Especially in a case of more compicated packages having bunch of patches to be applied on original sources. So we will try to use resulted folder (./build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/helloworld-1.0/) as an existing Makefile project to be imported to Eclipse.
Import Makefile project to eclipse
Open Eclipse and File –> New –> Project:
Then select C/C++ –> Makefile Project with Existing Code:
and navigate to your resulted package folder generated on OpenWrt package build. But in general you may point to any Makefile based application for embedded linux:
Here how imported project looks:
As you see it includes Host headers so we need replace them with headers from our toolchain and make few additional changes similar for changes we made in previous chapter for application built without Makefile.
Right mouse click on project –> Properties –> C/C++ Build –> Environment and add two additional environment varialbes:
and modify existing PATH variable by inserting following to the start of variable value:
Here four folders from our toolchain splitted with and endings with colon symbol:
click to Apply button and switch to C/C++ General –>Preprocessor Include Path, Macros etc. –> Providers and uncheck CDT Cross GCC Built-in Compiler Settings:
click to Apply button and navigate to C/C++ General –> Paths and Symbols –> Includes –> GNU C. Here add paths to headers from our toolchain:
Click to Apply and Close button.
Time to build project:
Then create Run (Run –> Run Configurations) and Debug (Run –> Debug Configurations) configurations as we did it in previous post for Makefile-less project. No any difference:
Try to run:
So we got opportunity of debugging real OpenWrt applications.