Compiling wxwidget applications in Netbeans

From WxWiki
Jump to: navigation, search

This tutorial has copiously copied (and updated) content from Netbeans and Compiling using Netbeans


Install Netbeans

First you need to install netbeans. To do that you will also need to install Java SE, since netbeans is normally a Java IDE. Easiest way to do that, is to first install a bundle of Java SE and netbeans, then install the C/C++ add-on pack for netbeans.

Download Java SE with netbeans, and follow the installation instructions available from Sun.

Install Netbeans C/C++ Pack, follow the instructions found at netbeans.org

Install a compiler

Since this tutorial is made from Linux Ubuntu, i have just installed GCC from apt-get. For Ubuntu users, just write in terminal:

sudo apt-get install build-essential

More information about gcc can be found at there site: [1]

Install wxWidgets

If you have not already done so, now is the time to install wxWidgets. Follow these instructions.

Test compiler in terminal

Now you need to make sure that the compiler and wxWidgets works outside netbeans. That way, if your test program doesn't work, at least you know you have not done anything wrong in Netbeans.

Copy/paste Robert Roeblings HelloWorld into a texteditor and save it as hello.cpp.

Open terminal and navigate to the folder where hello.cpp is saved. Then write:

g++ -c `wx-config --cxxflags` hello.cpp
g++ -o hello hello.o `wx-config --libs`
./hello

If that worked, then get on with the next step. Otherwise you should go through the first steps again, or try your luck in the wxForum.

For additional information on the usages and advantages of Wx-Config

Setup netbeans

First you need to create a new project: File -> New Project

In the wizard that shows up, choose the "C/C++" Categories: and "C/C++ Application" (if these options are not available, you have not installed the C/C++ pack properly). Press next, name your project whatever you like, and press finish.

Netbeans New Project 7 1.png

Copy/paste Robert Roeblings HelloWorld into the empty c++ file in netbeans. Save the file (ctrl-s)

Right-click project and choose "properties".

Netbeans Properties2.png

Configure the Compiler

In the project properties dialog select the submenu Build -> C++ Compiler -> Compilation Line

Add the following in "Additional options":

`wx-config --cxxflags`
   Note:  Those are leaning tic marks found on the tilde key (~).

C++ Complier Settings.png

Configure the Linker

Netbeans does not allow us to simply add command-line utilities (like our `wx-config --libs`) to help the linker so we have trick it a little. The trick, in the submenu Build -> Linker -> Libraries -> Libraries select the +++ icon to open the Libraries Dialog box...

C++ Linker Settings.png


C++ Linker Settings Add Option.png

Add the following in "Other Option":

`wx-config --libs`

C++ Linker Settings Add Option Dialog.png

Important: Using wx-config only works using wxGTK as shared library, otherwise, due to restrictions of gcc linker on static lib linking, you will have to setup Linker -> Additional Library Directories and Linker -> Libraries by hand

Remark: If you want your IDE to work with wxWidgets normally, there are some points you should check to make sure all goes ok.

  1. Create symlink "wx" to the folder with current wx version You can do it to simplify updating your wx version. Run in your console "ln -s /usr/include/wx-2.8 /usr/include/wx" Now the path "wx/wx.h" really exists under your filesystem and IDE will find everything it needs.
  2. Setting up include directories and preprocessor definitions. If you are using prebuilt packages with wx (such as deb package etc.) you won't find setup.h file in /usr/include/wx. There are really some different setup files for different configurations (you can read about it here. If you want your IDE to find the file, you should add it's path to your project's include dirs. Open the terminal and run "wx-config --cppflags". You will see there a substring "-I/usr/lib/wx/include/[config-name]". Remember it. Next, wx-config gives a definition of environment macros (i.e. "-D__WXGTK__"). Remember that macros name too. In NetBeans, open project properties and find Configuration Properties -> C/C++ -> C++ Compiler -> General. Paste the dir into "Include directories", copy that macros name into "Preprocessor Definitions". Save settings.

Now you can work normally. But remember to update that information if you are building wx with your own configuration or update it from repository.

Compile

All that is left is to build and run the program. You do this by doing the following:

- Select the "Main Project" within Netbeans.  (This identifies which Makefile to use)
- Build the project.  Run -> Build Main Project, and then 
- Run the project.  Run -> Run Main Project. 

These last four screenshots show how to select, build, and run the main project and how the program will execute.

Select the "Main Project" within Netbeans.

   Select Main Project.png

Build the project.

   Netbeans Build2.png

Run the project.

   Netbeans Run2.png

Ouput.

   Netbeans Success2.png

That's it. Hope you had succes with this tutorial.