This tutorial shows the basic steps of how to work with your
existing C++ application using Sun Studio IDE.
As an example, we will use the project "Sibsim". It's a small
open-source
scientific project which formats certain biological data. You could
find this project here: http://sourceforge.net/projects/sibsim.
The sequence of the steps in this tutorial is not optimal. This is
done intentionally.
We will face some typical problems and show how to solve them.
Preparing project
Download the project from the above url.
Extract the downloaded tarball into your home directory (let's refer to
is as /home/username/).
Go to the /home/username/sibsim-2.1.1 folder and run
./configure --prefix=/home/username/sibsim-2.1.1
We use --prefix parameter here to set up the project to have binaries
in the same directory as the project itself.
Importing project into Sun Studio
We will use "New Project" wizard to import our project.
- Choose File > New Project in the main menu.
- In the wizard, select C/C++/Fortran Development category.
- There are 4 types of projects under this category. Choose C/C++
Project From Existing Code

- Click Next
- On the next page you need to set up Makefile for the project.
Click Browse and choose /home/username/sibsim-2.1.1/Makefile:

- Let's leave it as is for now and proceed to next wizard page. We
will come back later and configure the build command. Click Next.
- To build your project, IDE needs only makefile, working
directory and target. Nevertheless, code assistance features (code
completion, hyperlink navigation, class view, etc.) need to know more.
They need to know the exact list of the project files. They also need
to know include search paths and macros.
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 already included in the
list:

- In this example, we don't need any further setup of source
files. Click Next.
- On the next page we specify name and location of the Sun Studio
project. Let's leave the default Project Name and use the original
project folder as Project Location (where the Sun Studio project will
be created). In this case IDE will create just one subfolder under the
original project folder with all needed files.

- Click Finish. You should see the newly created project in the
Projects window.
- To make sure Sun's make program works correctly with the
makefiles generated by the configure command, add the target
".POSIX:" to the project makefile sibsim-2.1.11-Makefile.mk. The
project makefile is available in the Important Files folder:

Configuring the project to use with code completion and class
browser
The project may not yet have been
correctly configured for code completion, code folding and class
browser. The first indication is an error sign in the lower-right
corner of the IDE window:
Another indication is that in some files (for example,
parse.cpp)
#include directives are underlined red:
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 managed project (Application,
Dynamic or Static Library). Usually managed projects are used
for creating project from scratch.
For such projects, all necessary information is stored in project
infrastructure; makefile is just generated.
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.
In 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.
Double-click error sign in the
lower-right corner of IDE window. You will see the following dialog

The list on the right contains all #include
directives that failed to resolve. If you select one, right list shows
all files that contains this #include directive. Here we
see that parser can not find libxml/xmlmemory.h file on the include
paths. This is a system library located in /usr/include/libxml2.
Add this directory to the include search path list:
Open project properties; select Parser
Configuration > Sun C++ Compiler. Add /usr/include/libxml2 to
"Include Directories" field.

Unfortunately, this version of Sun Studio
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.
Now code completion works correctly. Open
parse.cpp source file, type xmlMemory in the editor and press
<CTRL> Space, and the code completion pop-up will suggest two
choices how to complete the identifier:

Building the project
- Before we could build project, we need to tune Make settings.
Right click on project name in Projects window and choose Properties in
the context menu.
- In the Project Properties window choose Make node and edit Build
Command option. Just add install to default value to get ${MAKE}
-f Makefile install. The default value for clean option is correct.

- Press OK. Now we could build project. Press F11 key, or select
Build > Build Main Project main menu item, or press correspondent
toolbar button.
Running the project
- Try running the project. To do this you can select Run > Run
Main Project or press F6 key or use toolbar button. In the output
window you would see shows "No executable specified in the project".
- We need to set up the path to the binary of the project. Go to
the Project Properties again.
- Choose Make node and edit Build Result field. During
configuration we chose /home/username/sibsim-2.1.1 as default location.
So click Browse button, open bin folder and select file sibsim.

- Try now. The Terminal window would appear with a result of
program run.
- Let's add "--help" to program arguments to see some more useful
output
- Open Project Properties again. Go to Running node. Add --help
to the Arguments field.

- Try run again:

That's all. The project is ready and yuu can now code, run, debug
and profile the project using Sun Studio IDE.
(Last updated December 11, 2006)