1 (edited by irimi 2011-11-18 13:08:56)

Topic: OpenWrt C/C++ development with Eclipse Howto

Hi,

There is an OpenWrt/Eclipse Howto I would like provide:
It is exported as PDF (17 pages) and due to many screenshots the size is about 920KB.
[s]Maybe I can send it by email to someone who can integrate it into the wiki !?[/s]
Now available at
http://downloads.openwrt.org/docs/eclipse.pdf

Excerpt:"With Eclipse your are able to develop software for OpenWrt target devices  in a very comfortable
manner. Eclipse provides a complete development suite.
This document explains how to use Eclipse C/C++ IDE 3.7 (Indigo) with OpenWrt's  cross
toolchain, how to setup remote target device source level debugging and remote access via eclipse.
It is shown how to write, compile and debug programs for OpenWrt target devices."

irimi

Re: OpenWrt C/C++ development with Eclipse Howto

Or, perhaps you can upload your doc somewhere else and provide the link here to download?

Mazi

Re: OpenWrt C/C++ development with Eclipse Howto

Feel free to send the PDF to jow - at - openwrt.org, I'll upload it to the wiki server.

4 (edited by irimi 2011-11-18 09:55:53)

Re: OpenWrt C/C++ development with Eclipse Howto

The document is now hosted at

http://downloads.openwrt.org/docs/eclipse.pdf
resp. wiki page is http://wiki.openwrt.org/doc/devel/eclipse

Thank you, jow !

Re: OpenWrt C/C++ development with Eclipse Howto

I have done your tutorial. It's great, Thanks. But I have got a problem. I need some package in the sdk, for example libftdi libusb, libconfuse. I added it to the librarys with 'make menuconfig' and successfully but I can't add/find the libraries to the eclipse project.
Thx

6 (edited by irimi 2011-12-05 10:17:11)

Re: OpenWrt C/C++ development with Eclipse Howto

madwlabby wrote:

I added it to the librarys with 'make menuconfig' and successfully but I can't add/find the libraries to the eclipse project.
Thx

If your code uses specific libs I think you have to add these libs to your project settings:
Project Properties -> C/C++ Build -> Settings -> Compiler / Includes (add here specific includes)
and
Project Properties -> C/C++ Build -> Settings -> Linker / Libraries (add here static libs)
resp.
Project Properties -> C/C++ Build -> Settings -> Linker / Shared Library Settings

Good luck !

Re: OpenWrt C/C++ development with Eclipse Howto

Hi irimi

I'd also like to thank you for that great tutorial. It really saves you a lot of time and trouble. Thank you.

I have the same question as madwlabby. I am using latest backfire release and am having trouble remotely debugging the project with libraries.
For this project I am using libmicrohttpd library. I did make menuconfig and installed it (I selected * not M).

If I make both Makefiles, compile, copy and install on the device the application/package is working as it should.


In eclipse:
- Project Properties -> C/C++ Build -> Settings -> Compiler / Includes -> Include paths -> "/Home/User/openwrt/backfire/staging_dir/target-i386_uClibc-0.9.30.1/usr/include"
- Project Properties -> C/C++ Build -> Settings -> Compiler / Includes -> Libraries -> "microhttpd"
- Project Properties -> C/C++ Build -> Settings -> Linker / Libraries -> Library search path -> "/Home/User/openwrt/backfire/staging_dir/target-i386_uClibc-0.9.30.1/usr/lib"

The project builds normally (Project -> Build Project). When I try to debug it's working all the way till the breakpoint reaches d=MHD_start_daemon... (helloworld code available on their website).

**** Build of configuration Debug for project hellobrowser ****

make all 
Building file: ../src/hellobrowser.c
Invoking: Cross GCC Compiler
i486-openwrt-linux-gcc -I/home/User/openwrt/backfire/staging_dir/target-i386_uClibc-0.9.30.1/usr/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/hellobrowser.d" -MT"src/hellobrowser.d" -o "src/hellobrowser.o" "../src/hellobrowser.c"
Finished building: ../src/hellobrowser.c
 
Building target: hellobrowser
Invoking: Cross GCC Linker
i486-openwrt-linux-gcc -L/home/User/openwrt/backfire/staging_dir/target-i386_uClibc-0.9.30.1/usr/lib -o "hellobrowser"  ./src/hellobrowser.o   -lmicrohttpd
Finished building target: hellobrowser
 

**** Build Finished ****

gdb outputs:

warning: Can not parse XML target description; XML support was disabled at compile time
[New Thread 23243]
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
warning: .dynamic section for "/usr/lib/libmicrohttpd.so.5" is not at the expected address (wrong library or version mismatch?)
Error while mapping shared library sections:
/lib/libgcc_s.so.1: No such file or directory.
Error while mapping shared library sections:
/lib/libc.so.0: No such file or directory.
Error while mapping shared library sections:
/lib/libpthread.so.0: No such file or directory.
Error while mapping shared library sections:
/lib/ld-uClibc.so.0: No such file or directory.
Cannot find bounds of current function

I have been playing with this for two days now (try & error) without any breakthrough.
I'd really appreciate if you could provide a tutorial, guide, suggestion about how can one debug with libraries.
Thank you again.

Regards

Microsoft® MCC

8 (edited by irimi 2012-05-14 17:31:16)

Re: OpenWrt C/C++ development with Eclipse Howto

Hi,

mitja.gti wrote:

Hi irimi

/lib/libgcc_s.so.1: No such file or directory.
Error while mapping shared library sections:
/lib/libc.so.0: No such file or directory.
Error while mapping shared library sections:
/lib/libpthread.so.0: No such file or directory.
Error while mapping shared library sections:
/lib/ld-uClibc.so.0: No such file or directory.
Cannot find bounds of current function

I have been playing with this for two days now (try & error) without any breakthrough.
I'd really appreciate if you could provide a tutorial, guide, suggestion about how can one debug with libraries.
Thank you again.

Regards

Mmh, I'm not sure but it looks like if you are trying to execute & debug on your host computer directly !? I never tried that way.
Hence my question: what kind of target do you use resp. are you debbuging via  ssh gdbserver connecttion ?

Re: OpenWrt C/C++ development with Eclipse Howto

Hi

I'm sorry for my late response. I wasn't expecting you to reply so fast smile

Yes, I have followed your tutorial and am using ssh gdbserver.
I have openwrt in my virtualBox on another machine. As far as I can tell it's debugging there. The hello world from your tutorial works as expected.
I can provide video or print-screens.

I think debugging with libraries is extremely useful and will be in great help for everyone that's trying to develop something more serious than a hello world.

I'm no expert working with linux and open-wrt. I'm a developer in windows environment so this is all new to me (except C).

I appreciate your reply. Thank you.

Microsoft® MCC

Re: OpenWrt C/C++ development with Eclipse Howto

Ok, I see your problem.

I don't have any experience to debug with dynamic libs, but only with static libs.
I guess it's similar.

You can try this:
1. The libs you want to debug , you have to rebuild with CFLAGS option -g (to build them with debug info)
    You can change the OpenWrt/Package/Makefile , but the easiest and better way is to change to OpenWrt Toolchain settings: (ToolChain Options -> Build with debug information [*])
    Then call 'make dirclean && make world'
2.In the Eclipse / debugger configuration/ Source settings you have to add the path to source code of the library/package you want to debug: it is somewhere located in your .../build_dir/target*/lib*

With these two steps I was able to debug other OpenWrt  packages (e.g. lcd4linux) with eclipse.

Good luck !

Re: OpenWrt C/C++ development with Eclipse Howto

Hey guys!

great tutorial so far. Although I came across a problem in eclipse: I get an "unresolved inclusion: <iostream>" - error.
This is my console output. maybe u can help me out  lilttle. Thanks in advance!

make all
Building file: ../src/HelloOpenwrt.cpp
Invoking: Cross G++ Compiler
mips-openwrt-linuxg++ -I/home/marco/openwrt/trunk/staging_dir/target-mips_r2_uClibc-0.9.33.2/usr/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/HelloOpenwrt.d" -MT"src/HelloOpenwrt.d" -o "src/HelloOpenwrt.o" "../src/HelloOpenwrt.cpp"
/bin/sh: 1: mips-openwrt-linuxg++: not found
make: *** [src/HelloOpenwrt.o] Fehler 127

**** Build Finished ****

12 (edited by mitja.gti 2012-05-23 14:04:16)

Re: OpenWrt C/C++ development with Eclipse Howto

tzippy wrote:

Hey guys!

great tutorial so far. Although I came across a problem in eclipse: I get an "unresolved inclusion: <iostream>" - error.
This is my console output. maybe u can help me out  lilttle. Thanks in advance!

make all
Building file: ../src/HelloOpenwrt.cpp
Invoking: Cross G++ Compiler
mips-openwrt-linuxg++ -I/home/marco/openwrt/trunk/staging_dir/target-mips_r2_uClibc-0.9.33.2/usr/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/HelloOpenwrt.d" -MT"src/HelloOpenwrt.d" -o "src/HelloOpenwrt.o" "../src/HelloOpenwrt.cpp"
/bin/sh: 1: mips-openwrt-linuxg++: not found
make: *** [src/HelloOpenwrt.o] Fehler 127

**** Build Finished ****

Hi tzippy

right click on your project in Project Explorer, select Properties.
On the left side expand C/C++ Build, select Settings. From the tabs in the right side, select Tool Settings and then select Cross Settings.
On the right side you should now see two options (Prefix and Path). This is described in section 6.2 Tool command path (target specific) (irimi tutorial).
I suspect that you've included one folder too much, nevertheless the path set there is wrong.

if you use the command: ~/openwrt/trunk$ find ./staging_dir -path "./staging_dir/toolchain*"  -name *openwrt-linux
and you get a result: ./staging_dir/toolchain-i386_gcc-4.5-linaro_uClibc-0.9.32/i486-openwrt-linux
then the path you should set is something like this: /home/username/openwrt/trunk/staging_dir/toolchain-i386_gcc-4.5-linaro_uClibc-0.9.32 (note that there is no i486-openwrt-linux folder set here). Just to be safe, use the browse button wink

I hope this will help you.

Regards.

Microsoft® MCC

Re: OpenWrt C/C++ development with Eclipse Howto

thanks mitja.gti for your answer!

Actually that's ecaxtly what I did there. Here's a screenshot:
http://dl.dropbox.com/u/1144075/openwrt.png

Any other idea?

14 (edited by mitja.gti 2012-05-23 14:20:53)

Re: OpenWrt C/C++ development with Eclipse Howto

Yes, try the prefix: mips-openwrt-linux- (note the - at the end).

page 6/17 in irimi tuttorial

Hence for “Tool command prefix” we have to enter “mips-openwrt-linux-” for ar7xxx based  resp. “i486-openwrt-linux-” for generic x86 / e.g. vmware target device.

Microsoft® MCC

Re: OpenWrt C/C++ development with Eclipse Howto

mitja.gti wrote:

Yes, try the prefix: mips-openwrt-linux- (note the - at the end).

page 6/17 in irimi tuttorial

Hence for “Tool command prefix” we have to enter “mips-openwrt-linux-” for ar7xxx based  resp. “i486-openwrt-linux-” for generic x86 / e.g. vmware target device.

Thanks a thousand times!
That little minus character... smile

The Build finished but I also get this output:

"mips-openwrt-linux-g++: warning: environment variable 'STAGING_DIR' not defined"

Re: OpenWrt C/C++ development with Eclipse Howto

irimi wrote:

Ok, I see your problem.

I don't have any experience to debug with dynamic libs, but only with static libs.
I guess it's similar.

You can try this:
1. The libs you want to debug , you have to rebuild with CFLAGS option -g (to build them with debug info)
    You can change the OpenWrt/Package/Makefile , but the easiest and better way is to change to OpenWrt Toolchain settings: (ToolChain Options -> Build with debug information [*])
    Then call 'make dirclean && make world'
2.In the Eclipse / debugger configuration/ Source settings you have to add the path to source code of the library/package you want to debug: it is somewhere located in your .../build_dir/target*/lib*

With these two steps I was able to debug other OpenWrt  packages (e.g. lcd4linux) with eclipse.

Good luck !

I did the 1st section, but am having trouble with the 2nd. Which source setting? C/C++ Application or C/C++ Remote Application or both? Is the tab Source the one you're talking about?
You have quite some options available there (when you click add) and I'm not sure which one to choose.

Microsoft® MCC

Re: OpenWrt C/C++ development with Eclipse Howto

tzippy wrote:

The Build finished but I also get this output:
"mips-openwrt-linux-g++: warning: environment variable 'STAGING_DIR' not defined"

You're welcome tzippy.
I'm afraid I have never tried a C++ application. I also never got that warning so I'm afraid I can't help you with this one.
We could do a bunch of try & error stuff but I'm sure that would be a waste of our time. I guess someone with more experience should help you with this one.

Microsoft® MCC

18

Re: OpenWrt C/C++ development with Eclipse Howto

You can ignore the warning.
OpenWrt's gcc/g++ is patched to search all its libraries and includes relative to the $STAGING_DIR environment variable. If this environment var is not set, you get the warnign above.

Best is you do something like "export STAGING_DIR=/path/to/your/target-dir" prior to calling make. The target-dir is the directory that contains the "lib" and "include" subdirectories with includes and libraries for your target system.

I think eclipse should offer some option to export environment variables somewhere, put in the STAGING_DIR there.

Re: OpenWrt C/C++ development with Eclipse Howto

Irimi

I managed to get some other library working (libconfig - http://www.hyperrealm.com/libconfig/).
Here's what I did:
- Followed your 1st step
    ...but the easiest and better way is to change to OpenWrt Toolchain settings: (ToolChain Options -> Build with debug information [*]) Then call 'make dirclean && make world'
- In Eclipse right click on project and select properties
- C/C++ Build, Tool Settings, Cross GCC Compiler, Includes, Include paths -> add /home/user/openwrt/backfire/staging_dir/target-i386_uClibc-0.9.30.1/usr/include
- C/C++ Build, Tool Settings, Cross GCC Linker, Libraries, Libraries -> add config
- C/C++ Build, Tool Settings, Cross GCC Linker, Libraries, Library search path -> add /home/user/openwrt/backfire/staging_dir/target-i386_uClibc-0.9.30.1/usr/lib

Unfortunately I still can't get libmicrohttpd to work. Maybe it has something to do with the dependency libpthread or multithreading. I tried to add pthread to Libraries, but that didn't help.
When the debugging starts and I hit MHD_start_daemon I get a message "No source available for "0x...". If I set a breakpoint somewhere in the code it get's hit and I can debug the rest of it.

If you'll have the time and will, take a look at it.
You can download the library here: http://mirror.lihnidos.org/GNU/ftp/gnu/libmicrohttpd/libmicrohttpd-0.9.19.tar.gz (libmicrohttpd-0.9.19.tar.gz)
Makefile for the library is here: https://dev.openwrt.org/browser/packages/libs/libmicrohttpd/Makefile
Here is a simple HelloBrowser: http://www.gnu.org/software/libmicrohttpd/tutorial.html#hellobrowser_002ec
HomePage of the library: http://www.gnu.org/software/libmicrohttpd/

Thank you for all your help.

Regards

Microsoft® MCC

Re: OpenWrt C/C++ development with Eclipse Howto

mitja.gti

Sorry I don't have time to evaluate your settings in detail, actually OpenWrt is just a hobby during my spare time...

Since you don't have completed the 2nd step , you wont be able to debug with eclipse because gdb does not know where the source code is located.
As far as I know all(most?) source packages are extracted and built in build_dir/.., some build results are copied to staging_dir e.g. toolchain binaries. c-header , etc.

You have to change the debugger settings not the project properties settings.
Please see last picture of chapter 8 (gdb Debugger setup), there you can see the gdb "Source" settings window, on the right side next to "Debugger" settings:
open that window and add your desired "Source Lookup Path" somewhere located at build_dir/target*/libmircohttpd*.

Re: OpenWrt C/C++ development with Eclipse Howto

jow wrote:

You can ignore the warning.
OpenWrt's gcc/g++ is patched to search all its libraries and includes relative to the $STAGING_DIR environment variable. If this environment var is not set, you get the warnign above.

Best is you do something like "export STAGING_DIR=/path/to/your/target-dir" prior to calling make. The target-dir is the directory that contains the "lib" and "include" subdirectories with includes and libraries for your target system.

I think eclipse should offer some option to export environment variables somewhere, put in the STAGING_DIR there.

Yes. It's located at "Project Properties Settings / 'C/C++ Build'  / Environment".

But this environment variable seems to be a newer feature because I did not get that warning when I wrote the HowTo last year !?

22 (edited by ndarkness 2012-06-22 15:22:25)

Re: OpenWrt C/C++ development with Eclipse Howto

Hi!! I have followed all the steps of the walkthrough made by irimi, but I;m having a error which is

Description    Resource    Path    Location    Type
make: *** [src/HelloOpenwrt.o] Error 127    HelloOpenWrt             C/C++ Problem


This is due a wrong path when I try to compile??

thanks in advance!

ps: I'm compiling for backfire instead of trunk

Re: OpenWrt C/C++ development with Eclipse Howto

I'm afraid this topic has nothing to do with compiling packages. It's about remote debugging.

You've already posted 3 posts in 3 different topics. That will not help you solve your problem but it will only make it harder for you and the other people that are reading this forum.

Microsoft® MCC

24 (edited by like2learn 2012-12-22 05:21:46)

Re: OpenWrt C/C++ development with Eclipse Howto

The document is well written, thus it is an easy and pleasant task to setup my machine with Mint 14 Nadia.

I encountered a few troubles though and I solved them luckily.

1. "make defconfig" reports the following package are missing: 'ncurses', 'zlib', 'git'. 
     Troubless:
     pacman -S ncurses       -->   E: Unable to locate package ncurses
     pacman -S zlib               -->   E: Unable to locate package zlib
     Tips: add period at the end of packages.
      pacman -S ncurses.     -->   Bingo
      pacman -S zlib.             -->   Bingo

2. Trouble:
     pacman -S openssh-sftp-server          -->   E: Unable to locate package openssh-sftp-server
    Tips:
     sudo apt-get install openssh-server   -->   Cause there is no openssh-sftp-server in Ubuntu and Mint.

Good luck.

John

Re: OpenWrt C/C++ development with Eclipse Howto

eclipse configuration has changed since this OpenWRT with Eclipse Howto was published. The v 3.8 eclipse command File -> New -> C++ Project now shows only one toolchain option "GNU Autotools Toolchain". Is this the correct option for OpenWRT?


Should one use File -> New -> Makefile Project with Existing Code?

Any pros offer a little guidance, pls?