How to Configure Apache AGE and PostgreSQL for Debugging in Apache NetBeans IDE
Tags: apacheage, development, c, netbeans
Published: 2023-07-01 04:17:09

In the previous post, I showcased 10 NetBeans IDE tools to accelerate the software development process. One of them is Debugging. I attempted to solely use GDB in the terminal for application debugging. However, it was challenging to find the exact line of the code I was debugging and determine which function to debug. This made the process extremely slow. With this tool, it is easier to visualize variables and identify the specific line where issues occur in the code. In this post, I will provide a step-by-step guide to configuring Apache AGE in NetBeans to utilize the debugging tool.

## 1. Prerequisites

For this tutorial, I used the following resources:

- Ubuntu 22.04 LTS;
- NetBeans 18;
- Apache AGE 1.3.0;
- PostgreSQL 13.

If you don't have Apache AGE and/or PostgreSQL installed yet, you can follow these guides to install from the source code according to your operating system:

- [PostgreSQL with Apache AGE installation on Windows with WSL](https://dev.to/carlasanches/easy-guide-to-install-and-configure-postgresql-with-apache-age-on-windows-n6p);
- [Installing Apache AGE with Docker on Windows](https://dev.to/markgomer/installing-apache-age-with-docker-on-windows-e22);
- [PostgreSQL with Apache AGE installation on Ubuntu](https://dev.to/carlasanches/step-by-step-guide-to-install-apache-age-and-postgresql-via-package-management-on-ubuntu-259l);
- [Easy Installation of PostgreSQL, AGE & Age-viewer on Mac](https://dev.to/maruf13/installation-of-postgresql-age-on-mac-4gc9).

## 2. C/C++ Environment Setup

By default, when creating a C++ project, NetBeans offers the following options:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ei6iy8jogdzcgf5foun.png)

To configure full support for C/C++ projects, we need to add a plugin. In the top toolbar, go to **Tools > Plugins**. Then, select the Settings tab and check the option **NetBeans 8.2 Plugin Portal**:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uxlmlq5nl4dlnats1hl4.png)

Next, select **Available Plugins** tab and click **Check for Newest** button. The option for C/C++ should appear. Check this option and click on the **Install** button. A new window will open. To proceed with the installation, click **Next** and accept the terms and license agreements. You will also see a selection button next to the word **Plugins**. This button indicates all the features that come with the installation. Finally, click on **Install** to complete the process.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0bwnmcor5rxba9q5g2m1.png)

The installation may take a few minutes to complete. Another pop-up window may appear at the end, asking for confirmation. Click on **Continue**, and the installation will finish successfully.

To configure the debugging and compilation tools, go to the top toolbar and select **Tools > Options**, then click on the **C/C++** tab. In the **Build Tools** section, make sure that the directories for the tools are correctly specified:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0f68qq1bjqsvue5tn0r.png)

## 3. Importing Projects in NetBeans

After installing the plugin, you will notice that new options have appeared for creating C/C++ projects. Go to **File > New Project > C/C++** and select option **C/C++ Project with Existing Sources**. Next, I will explain how to create projects for the source code of PostgreSQL and Apache AGE.

### 3.1. PostgreSQL

Select the directory of the PostgreSQL repository. You can leave the options marked as default and only change the **Select Configuration Mode** to **Custom**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9e5p33ap2ddl515a3bs7.png)

NetBeans will automatically find the PostgreSQL configuration file. Keep the option **Pre-Build** selected, and then we can configure the compilation flags. In the **Arguments** section, set `CC=${IDE_CC}` to configure the compiler to the directory specified in the last step of the previous section. A _very important_ step is to define the flags for debugging and installation. Set `CFLAGS="-g3 -O0" --enable-cassert --enable-debug` for debugging, and `--prefix` pointing to the installation directory of PostgreSQL. In my case, it is `--prefix=/usr/local/postgresql/13.0`.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jlnwjddqyip62wm38mjl.png)

In the next step, specify the working directory, the commands used for clean and build, and whether you want these commands executed as soon as the configuration is finished. Keep the option **Clean and Build After Finish** selected. The working directory should be the directory of the PostgreSQL source code. Use `${MAKE}` to configure the make command to the directory set in the last step of Section 2.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bldo2oc21z4byv2c2mjs.png)

The next step is to select the directories where the relevant source code for the project is. Since we are only working with PostgreSQL, you can leave the options as default.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0jlmw7eovbkq5mpy4hk.png)

Next, we select the directories to include. Choose the option **Manual Configuration** and click **Edit** in the **Include Directories** field. Click **Add** to add a new folder and browse for the directories `/src/include` and `/src/fe_utils` within the PostgreSQL source code directory.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpvjxs44fhpyqp417j6b.png)

Finally, let's define a name for the project and the directory where it will be saved. To avoid mixing the project with the PostgreSQL Git directory, I created a separate directory called `netbeans-projects`.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/si7whag7pv3taahycckz.png)

Click on **Finish**, and if you have selected the option to **Clean and Build after Finish**, you will see in the integrated terminal that the command will compile the source code and return the following message, indicating that PostgreSQL has been successfully compiled.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9nqs8m6k7he6yzyhjg8f.png)

You can complete the installation through the integrated terminal by accessing the working directory. Click the **Output** tab and select the option on the left, **Open Working Directory in Terminal**. Then, run the command `make install` to finalize the installation.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bfw9ngji8mr3a0bu0qvj.png)

At the end of the installation, the terminal will return the message **Installation complete**.

### 3.2. **Apache AGE**

Apache AGE follows the step-by-step process for configuring PostgreSQL. Therefore, I will only explain the different settings from the previous walkthrough.

After creating a new project and selecting the Apache AGE source code directory in the **Pre-Build option**, export the environment variable `CFLAGS="-g3 -O0"` to enable debugging.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9t9zvfktuklttgjkxg2c.png)

Next, in the Build Actions option, configure the **Clean Command** as `${MAKE} PG_CONFIG=/usr/local/postgresql/13.0/bin/pg_config distclean` and the **Build Command** as `${MAKE} PG_CONFIG=/usr/local/postgresql/13.0/bin/pg_config install`. Note that the `PG_CONFIG` variable will point to the `pg_config` file in the PostgreSQL installation directory.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ok4q2xsol5ndzxf7hlj.png)

Skipping to the **Code Assistance Configuration** step, add the `src/include` folder inside the age source code directory, as well as the directories `/src/include` and `/src/fe_utils` from PostgreSQL. This will help prevent error suggestions when opening a code file in the IDE.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nmxv6s9j838lw05vxuxd.png)

Continue with the remaining configurations following the step-by-step process for PostgreSQL. In the end, if you have selected the option to **Clean and Build after Finish**, you will see in the integrated terminal that the command will compile the source code and return the following message, indicating that AGE has been successfully compiled and installed.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8bctnaggz0mlmymnvxgq.png)

## 4. **Conclusion**

In this tutorial, I have provided a step-by-step guide on how to configure a NetBeans project to debug the Apache AGE source code. If you found this helpful, don't miss the next tutorial, where I will walk you through the process of debugging.

## 5. Contribute to Apache AGE

Apache AGE website: https://age.apache.org/
Apache AGE Github: https://github.com/apache/age

## 6. **References**

This tutorial was based on the article _Working with Eclipse_, available at **https://wiki.postgresql.org/wiki/Working_with_Eclipse**.