C/C++ Projects Quick Start TutorialContributed by Ann Rice and maintained by Susan Morgan The following short tutorial takes you through the basic steps of creating and configuring a C or C++ project in NetBeans IDE 7.2. Contents ![]()
RequirementsTo follow this tutorial, you need the following software and resources.
See the NetBeans IDE 7.2 Installation Instructions and Configuring the NetBeans IDE for C/C++/Fortran Sample Projects Just want to play with some projects? In the IDE, choose File > New Project, then open the Samples category, the C/C++ subcategory, and the C/C++ subcategory. The IDE provides several sample C and C++ projects to help you familiarize yourself with the IDE. Creating C and C++ ProjectsNetBeans C/C++ support lets you create C and C++ Application and Library projects with generated makefiles, as well as C and C++ projects with existing sources. You can build, run, and debug your project on the local host (the system from which you started the IDE) or on a remote host running a UNIX® operating system. For information on specifying the tool collection for your project, and on defining and using remote hosts, see Defining Your C/C++ Project's Development Environment. With a C/C++ Application, Dynamic Library, or Static Library project, the IDE controls all aspects of how your application is built, run, and debugged. You specify project settings when creating the project and in the Project Properties dialog box. The IDE generates a makefile in which all of your settings are stored. Creating a C/C++ Application Project
A project is created with logical folders. A logical folder is not a directory. It is a way for you to organize your files and does not reflect where the files are physically stored on disk. Files added to logical folders are automatically part of the project and are compiled when you build the project. Files added to the Important Files folder are not part of the project and are not compiled when you build the project. These files are just for reference and are convenient when you have a project with an existing makefile. Switching Between the Logical View and the Physical View of the ProjectA project has both a logical and a physical view. You can switch between the logical view and the physical view of your project.
Adding Files and Folders to Your ProjectYou can add logical folders to your project.
You can add both files and folders to an existing folder. Logical folders can be nested. Adding New Files to Your ProjectYou can add new files to your project.
The newfile.cpp file is created on disk in the directory specified in the wizard and added to the Source Files folder. You can add any kind of file to this folder, not only source files. Adding More New Files to Your Project
The newfile.h file is created on disk in the directory specified in the wizard and added to the Header Files folder. Adding Existing Files to Your ProjectYou can add existing files to your project in two ways:
Do not use New menu item to add existing items. The Name and Location panel will tell you the file already exists. Setting Project PropertiesWhen the project is created, it has two configurations, Debug and Release. A configuration is a collection of settings used for the project, which allows you to easily switch many settings at once when you select a configuration. The Debug configuration builds a version of your application that includes debug information. The Release configuration builds an optimized version. The Project Properties dialog box contains build and configuration information for your project. To open the Project Properties dialog box:
You can modify the build tool defaults, compiler settings, and other configuration settings in the Project Properties dialog box by selecting a node in the left panel and modifying the properties in the right panel. Select some of the nodes and property values and notice the properties you can set. When you set General properties, you are setting them in all configurations of the project. When you set Build, Run, or Debug properties, you are setting properties in the currently selected configuration. Managing ConfigurationsProperties changed in the Project Properties window are stored in the makefile for the current configuration. You can edit the default configurations or create new ones. To create a new configuration:
You have created a new configuration that will compile the application with a different set of options. Setting Source File PropertiesWhen you set the project properties for your C or C++ project, the relevant properties apply to all files in the project. You can also set some properties on individual files.
Building Your ProjectTo build your project:
You can build, clean, or both clean and build the project by choosing actions from the Run menu. The project also keeps object files and executables from different configurations separate, so you do not have to worry about mixing files from multiple configurations. Compiling a Single FileTo compile a single source file:
Note. Single file compilation is not supported for the project type C/C++ Project With Existing Sources. Running a ProjectTo see how to run a project, you will use the IDE's sample Arguments project. The Arguments program prints command-line arguments. Before running the program, you will set some arguments in the current configuration. Then you will run the program. To create the Arguments project, set some arguments, and run the project:
Creating a C/C++ Project With Existing SourcesWhen creating a C/C++ Project With Existing Sources, the IDE relies on your existing makefile for instructions on how to compile and run your application. In this exercise, you download and install the sources for the open source Loki C++ library. Loki requires the Pthreads library to build, which is available by default on Linux, Solaris, and Mac OS X. If you are using Windows, you must download the Pthreads library before you can create a project using the Loki source files. Creating a Project With Existing Sources
Creating a C/C++ Project from a Binary FileYou can create a C/C++ project from an existing binary file.
Building and Rebuilding Your ProjectTo build the project:
To rebuild the project:
Next StepsSee Editing and Navigating C/C++ Source Files for a tutorial on using the advanced navigation and editing features in NetBeans IDE to view and modify your source code. | Documentation |