Using NetBeans to compile C/C++ code for Omega
-
I am a great fan of NetBeans as a development IDE.
So based on what I found out as documented here: https://community.onion.io/topic/9/how-to-install-gcc/22 I decided to see if I could build usable C/C++ code using NetBeans.In the following:
- Everything is being done on KUbuntu-10.04 running a VirtualBox VM
- I assume that you know how to obtain and install NetBeans - I am using version 8.1
With NetBeans installed and the tool chain set up as described in the above reference, you will need to do the following:
- Ensure you have C/C++ enabled in NetBeans:
- Navigate to Tools->Plugins->Installed and ensure C/C++ is activated
- Set up access to the Omega toolchain (in what follows, <tc_dir> is the directory where you unpacked the tool chain)
- Navigate to Tools->Options->C/C++->Build Tools
- Click on Add
- In the dialog that comes up, enter the following:
- Set Base Directory to **<tc_dir>/OpenWrt-Toolchain-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin
- Set Tool Collection Family to GNU
- Set Tool Collection Name to anything you want. I use OmegaCross - note this will be referenced later
- Click on Ok
- Select theTool Collection youhave jsut create and set the following fields:
- C Compiler = <tc_dir>/OpenWrt-Toolchain-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc
- C++ Compiler = <tc_dir>/OpenWrt-Toolchain-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-g++
- Create a C/C++ project, ensuring you set Tool Collection to the tool collection you created above (e.g. OmegaCross)
- Create and edit etc. the required c/c++ and h files
- Perform a Clean and Build on the project
- The built program will be found under the dist sub-directory in your project directory. Copy it to your Omeag nd run it
-
Update on this for creating and using C/C++ Dynamic Libraries for Omega using NetBeans.
1. Creating a Dynamic Library
- In NetBeans, create a project of type: C/C++ Dynamic Library - make sure that the Tool Collection is set to the Omega cross comipler
- Create all the source files for your library and built it
- Copy the built .so file from under the project dist directory to the /lib directory on your Omega
2. Creating Program That Uses Library
- In NetBeans, create a project of type: C/C++ Application - make sure that the Tool Collection is set to the Omega cross compiler
- Right click on the project you have just created and select Properties
- Under Build->C Compiler (and/or Build->C++ Compiler as required for your project), click on the ... button against Include Directories
- Add the directory that contains the .h files of your Dynamic Library. I selected to add this as Relative but other options may work. This is so that your application can find the .h files that you will need to reference in your application source
- Under Build->Linker click on the ... button against Libraries
- Click on Add Project... button
- Select your dynamic library project and the required Configurations and click on Add. This is so the linker knows how to link to the dynamic library
- Create all the source files for your application and built it
- Copy the built file from under the project dist directory to wherever you want on your Omega and run it on your Omega. it should pick up the dynamic library you previously built and installed
-
@Kit-Bishop Can I put this up on the Wiki?
-
@Boken-Lin Of course you can I was thinking of suggesting that I put together a document or something to go on the Wiki so it would be easier to find in case people wanted it.
-
@Kit-Bishop Thanks!
-
@Boken-Lin FYI: I can confirm that all the above works well.
I have used it to produce an alternative GPIO C++ library and associated test program because I wanted some additional/different features. It is all working well
I still have some work to do on it to tidy it up and add some additional features, but will post it here when I'm done in case it is of use to others.Specific features I still want to add are:
- PWM output using threads rather than forking processes
- Ability to attach an interrupt service routine that gets called when an input pin changes state
-
@Kit-Bishop Yeah, #2 would be really handy. Have you had a chance to take a look at this: https://github.com/OnionIoT/gpio-irq? This sends an IRQ when the pin changes state. What we want to do is to wrap that into the edge fs interface like how it is on the raspberry pi.
-
@Boken-Lin With reference to #2 - yes, have seen the gpio-irq code and will be incorporating something like it in to my new GPIO code. May be a few days a way yet before the work is done.
-
@Kit-Bishop Looking forward to it!!
-
@Boken-Lin I have a small question in relation to the code I am developing.
I want to ensure that the code does not permit GPIO operations on pin numbers that are not usable GPIO pins.
I think I have deduced that GPIO operations should only be performed on the following set of pins and no others:0, 1, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18, 19, 23, 26
Can you confirm or correct me. Thanks
-
NOTE: Edit original posting because I found an oddity with NetBeans when using a Dynamic Library
What I find to be a useful update to the NetBeans set up for Omega:
I am lazy and don't like to have to do additional work and prefer to automate things where I can.
Consequently, I have found a way to get NetBeans to transfer the result of building an Omega project to the Omega. This works so long as you have access to your Omega from your host system:- Ensure that you have pscp installed on your host system. pscp is a variant of scp that allows you to specify the password for the scp connection - in general not highly recommended for security reasons but assume that it won't cause any issues here
- In NetBeans, right click on your project and select Properties
- Go to Run under Categories and click on the ... button against Run Command
- Enter the following with appropriate substitutions:
For a standard program use:
pscp -scp -pw "<omega_password>" ${OUTPUT_PATH} root@<omega_ip_address>:<dest_dir>/.
And for a Dynamic Library use:
pscp -scp -pw "<omega_password>" ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/* root@<omega_ip_address>:<dest_dir>/.
Where:- <omega_password> is the pass word for your Omega - default is onioneer but you may have changed it
- <omega_ip_address> is the IP address used to access your Omega - probably 192.168.3.1
- <dest_dir> is the destination directory for the file on your Omega - you may omit <dest_dir>/ if you want and the file will be placed in the /root directory.
For a Dynamic Library, I normally use /lib for <dest_dir> to put the library directly to the required directory
- Having build your project, right click on your project in NetBeans and select Run - the built file will be transferred to your Omega.
@Boken-Lin You may want to add this to the Wiki entry if considered useful.
-
@Kit-Bishop The GPIO ports looks right
-
@Boken-Lin Thanks - I'll go with that then
-
PLEASE NOTE
I have edited my original instructions above for getting NetBeans to transfer your built file to your Omega because of an oddity I found in how NetBeans deals with Dynamic Libraries