Source code file content

Revision: 2

import
» Project Revision History

» Checkout URL

web-content / trunk / docs / howto-existent / howto-exist.html

Size: 11170 bytes, 1 line
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1251">
	<TITLE>Developing Existing Application With the NetBeans C/C++ Development Pack</TITLE>
	<META NAME="CREATED" CONTENT="20061202;17291189">
	<STYLE>
	</STYLE>
</HEAD>
<BODY LANG="en-US" DIR="LTR">

<H1 ALIGN=CENTER>Developing Existing Application <BR>
With the NetBeans C/C++ Development Pack</H1>

<P>The following short tutorial takes you through basic steps of
developing your existing C/C++ application 
using the 
NetBeans&trade; C/C++ Development Pack.
</P>

<p>The sequence of these steps is not "ideal"; this is done intentionally.
We will face some typical problems and solve them; we would not face this problems
if all information we entered was absolutely correct and complete.
But we are not in an ideal world.
So we will go the most typical way instead.
</p>

<P>We will use Squirrel Shell project as an example. Squirrel Shell is an open source project taken from Internet: 
<A href="http://sourceforge.net/projects/squirrelsh"> http://sourceforge.net/projects/squirrelsh</A>. 
Squirrel Shell is made as a cross-platform alternative to system shells like bash in Linux 
and command.com/cmd.exe in MS Windows. It is based on the scripting language named 
<A HREF="http://sourceforge.net/projects/squirrel">"Squirrel"</A>.
</P>

<BR><H2>Configuring project</H2>

<P>Go to project page
(<A href="http://sourceforge.net/projects/squirrelsh"> http://sourceforge.net/projects/squirrelsh</A>),
download archive with sources and extract them into some directory. 
<!-- C:\Documents and Settings\vk\squirrelsh-1.0 --></P>

<P>The Squirrel Shell is an <a href="http://www.gnu.org/software/autoconf">autoconf</a> project. 
For now there is no autoconf support in  
NetBeans&trade; C/C++ Development Pack. 
You have to configure the project manually.
Launch cygwin shell, change directory to the one you extracted project into 
and run <code>./configure</code>.</P>

<BR><H2>Creating a project</H2>

<p>You can create a project using a wizard. If you know every minute detail concerning your project, and understand, 
which of these details are important for IDE to work properly, then your project is completely ready after 
you finish the wizard.</p>

<p>In most situations though, you use default values for many fields, 
and correct these values via project properties dialog later on, when you encounter a problem.
Our Squirrel Shell example is the case.</p>

<ol>
    <li><p>Open the New Project wizard by choosing File &gt; New Project.</p></li>
    
    <li><p>Select the C/C++ Development category.</p></li>

    <li><p>Select C/C++ Project From Existing Code and click Next. 
    You will see the following wizard page.</p>

    <p><img src="new-project-2a.png"/></p>
    
    Fill the "Existing Makefile" field: 
    press "Browse" button, find Squirrel project location, and select Makefile.
    After that other fields (except for "Build result") are automatically filled with default values.
    <p>You can fill "Build Result" field if you know what binary is produced by the project 
    or you may postpone this and leave the field empty. Since we do not know what particular file will 
    Squirrel Shell produce, we leave this field empty and click next.</p>
    </li>
    
    <!-- <p><img src="new-project-2b.png"/></p> -->
    
    <li> Add source files to project.
    
    <p> To make your project, IDE needs only makefile, working directory and target.
    Nevertheless, code assistance features (code completion, hyperlink navigation, class view, etc.)
    needs to know more. They needs to know the exact list of the project files. 
    They also need to know include search paths and macros.</p>
    
    <p>The wizard scans project directories for source files and adds files that are found to projects. 
    You can specify several directories. You can also specify file types to search for (headers, sources or both).
    By default, your project working directory is searched for.
    </p>
    
    <p><img src="new-project-3.png"/></p>

    <p>Note that you can also add files to your project later on, via "Add Existing From Folders" item 
    in Project Explorer context menu</p>
    
    <p>You can also specify two fields that are used by built-in parser: 
    include directories (corresponds to <code>-I</code> compiler option) 
    and macros (corresponds to <code>-D</code> compiler option). 
    You can also specify both later on.
    </p>
    </li>

    <li><p>Enter project name and location. 
    Here you enter the name and location of 
    NetBeans&trade; C/C++ Development Pack    
    project that contains all necessary infrastructure.</p>
    
    <p>By default this project is placed in a separate directory, 
    not in the directory your makefile and sources reside.
    (Note that a trailing "1" is added to your initial project directory).
    You can make these directories the same; 
    but this can cause name conflicts and version control system problems.
    </p>

    <p><img src="new-project-4.png"/></p>
    
    Press Finish.
    
    </li>

</ol>

<BR><H2>Building project. Take one.</H2>
    
<p>Press F11 key (or select Build &gt; Build Main Project main menu item; or press correspondent toolbar button)</p>

<P>See the following messages in output pane</P>

<pre>
    Specify one of these targets:
    x86-debug
    x86-release
    x64-debug
    x64-release
</pre>

<p>This mean our makefile does not have default target, so we should specify one explicitly</p>

<BR><H2>Entering correct make target.</H2>

<p>Let's assume we are on 32-bit x86 machine. 

<p>Go to the project properties 
(either via "File" &gt; "Squirrelsh-1.01 Properties" or via "Properties" item on the project explorer context menu).
Select "Make" node in propertied tree:</p>

<p><img src="project-properties-make.png"/></p>

<p>Append <code>x86-debug</code> to "Build Command" field.</p>

<p>We'd surely like to be able to build release version either; 
we'll describe how to add configurations in the end of this article:
now our main goal is to make the project build at least for one configuration.</p>

<BR><H2>Building project. Take two. Running project.</H2>

<p>This time it builds perfectly.</p>

<p>Try running the project. 
To do this you can select Run &gt; Run Main Project or press F6 key or use toolbar button.</p>

<p>It shows "No executable specified in the project". 
Let's go to the project properties, select "Make" in the properties tree and fill "Build Result" field. 
In our case it's <code>../squirrelsh-1.0/bin/squirrelsh.exe</code> 
(The path is relative to the project infrastructure directory).</p>

<p>We might fill this field in project creation wizard if we knew the exact name and location of the binary. 
On the other hand it's more convenient to do this now since the project is already built, so now we can 
just select binary from the list (press "..." button to the right of "Build Result" field).
</p>

<BR><H2>Correcting information necessary for code assistance</H2>

<P>At this moment you may see some indications that IDE needs some more information about your project.</P>

<p>The first indication is an error sign in the lower-right corner of the IDE window:</P>

    <p><img src="error-badge.png"/></p>
    
<br>    
<p>Another indication is that in some files (for example, <code>common.h</code>)
<code>#include</code> directives are underlined red:

    <p><img src="error-highlight.png"/></p>

<br>
<p>What does this mean, you wonder - the project is built successfully?!</p> 

<p>This concerns built-in parser and thus code assistance functionality (completion, hyperlink, etc.). 
This does not concern build.
This would not happen if you use <i>managed</i> project (Application, Dynamic or Static Library). 
Usually <i>managed</i> projects are used for creating project from scratch.
For such projects, all necessary information is stored in project infrastructure; 
makefile is just generated.
 </p>
 
 <p>Since we are working with existent, i.e. makefile-based project, 
only makefile contains such important compiler options as -I and -D.
Built-in parser that is used for code assistance knows nothing about these options.
 </p>

<p>
For this release, the problem of extracting these options from makefile is not solved.
So you have to tell IDE correct values for these options 
in order to make code assistance (code completion, hyperlink navigation, class view, etc.)
work properly.
 </p>
 
<p>Double-click error sign in the lower-right corner of IDE window.
 You will see the following dialog</p>

    <p><img src="failed-includes-dialog.png"/></p>

<p>The list on the right contains all <code>#include</code> directives that failed to resolve.</p>

<p>If you select one, right list shows all files that contains this <code>#include</code> directive.</p>

<p>Here we see that parser can not find squirrel.h file on the include paths. 
We can go to project explorer and understand that it is in "include" subdirectory.
Add this directory to the include search path list:
</p>

<p>Open project properties; select Parser Configuration &gt; GNU C++ Compiler. 
Add <code>../squirrelsh-1.0/include</code> to "Include Directories" field.</p>

    <p><img src="project-properties-parser.png"/></p>

<p>Note that this field content is relative to project infrastructure directory</p>

<p> Unfortunately, version 1.0 of the  
NetBeans&trade; C/C++ Development Pack
has a problem: it's built-in parser does not reparse the project after it's options are changed.
So you have to either close and reopen project to put these options into effect 
or just switch code assistance off and back on for this project. You can do this via 
"Code Assistance" checkbox menu item in Project Explorer context menu.
</p>

<BR><H2>Adding configurations.</H2>

<p>We added only <code>x86-debug</code> target. Now since our project works ok, 
we'd like to be able to build both debug and release versions.</p>

<p>Go to project propertied and press "Manage Configurations" button.</p>

<p>Rename "Default (active)" configuration to the "Debug". Then press "Copy" button. 
It will create "Copy_of_Debug" configuration. Rename it to "Release" and press OK.</p>

<p>Note that "Configuration" drop-down box at the top of Project Properties dialog now contains three items:
<ul>
    <li>Debug</li>
    <li>Release</li>
    <li>&lt;All Configurations&gt;</li>
</ul>

<p>Select "Release" and change <code>x86-debug</code> to <code>x86-release</code>. Press OK.</p>

<p>Note that you can easily switch configurations via drop-down box that resides in the main toolbar.
Try rebuilding both Debug and Release; note the difference in compiler options.
</p>

<!--
<BR><H2>What if we knew all of the above from the very beginning.</H2>

In the ideal world, we knew all of the above from the very beginning.
In this case we would enter all necessary information in project creation vizard:
<ul>
    <li>Made debug and release configurations</li>
</ul>

In this case we would have perfectly working project just after we finished wizard.
-->

</BODY>
</HTML>

Project Features

About this Project

CND was started in November 2009, is owned by DimaZh, and has 198 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20160708.bf2ac18). © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close