3

I want to start C++ development with NetBeans 15, on Lubuntu Kinetic Kudu (22.10).

I installed first build-essential

sudo apt install build-essential

g++ --version
g++ (Ubuntu 12.2.0-1ubuntu1) 12.2.0

gcc --version
gcc (Ubuntu 12.2.0-1ubuntu1) 12.2.0

When selecting Tools > Options > C/C++ it says that either ccls or the clangd language protocol servers are needed.

I installed ccls

sudo apt install ccls

ccls --version
Ubuntu ccls version 0.20220729-1
clang version 14.0.6-2

Not sure if I should have installed clangd instead or in addition to ccls.

Now when I start NetBeans 15 choosing the C/C++ option it automatically selected the path to ccls

/usr/bin/ccls

Now I wanted to start a first Hello World C++ project, but somehow it looks complicated.

I would like to use the highest possible C++ standard version. The installed build-essential comes with version 12.2, and here for example https://gcc.gnu.org/onlinedocs/12.2.0/ I assume that for C++ it supports Standard 20 or even higher. I looked into it the very first time.

1. Choose Project: File > New Project > C/C++ > Lightweight C/C++ Project
2. Location: Project Path 
   I created a new folder myfirstcpp in /home/me/NetBeansProjects and selected it on this step.
3. Editor: Compile Commands
   Here no clue what to specify. 
   I leave it empty and proceed.
4. Build: "Configuration Name", "Build", "Clean" and "Run"
   Here no clue what to specify. 
   I leave it empty and proceed.

The project is created but completely empty, no artifact created upfront.

I created a CPP file and copied the following code from the web

// C++ program to display "Hello World"
// Header file for input output functions
#include <iostream>
using namespace std;
  
// Main() function: where the execution of program begins
int main()
{
    // prints hello world
    cout << "Hello World";
  
    return 0;
}

But the editor shows a yellow warning triangle stating compile commands not configured. Also no option to run that simple Hello World programm, every Run option is greyed out.

Obviously I have to configure steps 3-4 properly. How?

Update on @skomisa comment

I found that post before, but placing a .ccls file with the exact same content

/home/me/NetBeansProjects/myfirstcpp/.ccls:
g++
-xc++
-Iinclude
-std=c++17

didn't change anything. Now I tried again, and after clicking around in the Project Properties in the Editor category by removing and adding the path /home/me/NetBeansProjects/myfirstcpp/.ccls to the .ccls file, switching into the Build category without changing anything, all of a sudden the Run options were active.

Weired, looks buggy to me... also when I closed NetBeans, restarted, everything was again greyed out, until I clicked around again in the Project Properties until the Run options appeared active.

However, when I clicked the Run Project (myfirstcpp) option I got this exception in the Output window

Exception in thread "main" java.io.IOException: Cannot run program "": error=2, No such file or directory
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
    at org.netbeans.modules.cpplite.project.runner.Runner.main(Runner.java:35)
Caused by: java.io.IOException: error=2, No such file or directory
    at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
    at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:315)
    at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:245)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)
    ... 2 more

Either the content in the .ccls file is not correct or incomplete, or in addition the Build category has to be configured too.

I use OpenJDK

java --version                                                                                                                                    
openjdk 18.0.2.1 2022-08-18                                                                                                                                                        
OpenJDK Runtime Environment (build 18.0.2.1+1-1)                                                                                                                                   
OpenJDK 64-Bit Server VM (build 18.0.2.1+1-1, mixed mode, sharing)

if this is relevant.

neblaz
  • 683
  • 10
  • 32
  • I can't find any current NetBeans documentation on how to set things up for C++ development. The CPPLite Kit plugin is pre-installed on NB15 (**Tools>Plugins > Installed**), and states _"A temporary lightweight C/C++ support. The editing features require ccls to be installed"_. So yes, you definitely want to use ccls rather than clangd. But I'm on Windows and it looks like you also have to build **ccls** yourself, and [it seems you need Visual Studio 2017 to do that](https://github.com/MaskRay/ccls/issues/569)! – skomisa Sep 11 '22 at 02:14
  • Anyway, once you have **ccls** installed, it looks like your CPP project will need a **.ccls** file, and this may be the step you are missing. See [this SO answer](https://stackoverflow.com/a/71081135/2985643) for more information on that. This new approach seems like a huge backward step in C/C++ support on NetBeans, which worked fine with the old plugin/wizard on version 8.x. – skomisa Sep 11 '22 at 02:18

1 Answers1

3

Just installed NB15 on Ubuntu 22.04 and running C++ (using gcc/g++12) project. Follow mostly from

https://stackoverflow.com/a/66832862/6760184

  • Enable C++:

    • Open Tools/Plugins/Settings
      • Check NetBeans 8.2 Plugin Portal
      • Go back to Available Plugins and press Check for Newest button.
      • Check C/C++ plugin and press Install button.
    • specify unpack200 location
      • Pre-13 OpenJDK is bundled at, for example, /usr/lib/jvm/java-11-openjdk-amd64/bin/unpack200 It is gone after version 14.
      • Or, install with sudo apt install mlocate and use ls -l `locate unpack200` to locate unpack200.
  • Enable C++17

  • Enable C++20

    • Right click project Properties/C++ Compiler/Additional Options and add

      -std=c++20

Hope this helps!

Ping Chia
  • 61
  • 4
  • 2
    [1] That describes the old way of setting up the C/C++ environment in earlier versions of NetBeans. My understanding is that the question is specifically asking about how it should be done on NetBeans 15 using the **CCLS configuration** tab under **Tools > Options > C/C++**. [2] You have included a link that will automatically download a zip file. Remove that. Instead link to the page where the zip download is shown. – skomisa Sep 15 '22 at 20:47
  • Dear @skomisa Thanks for the advise, change link accordingly. I saw the title with GCC included, so I thought the old way might help. – Ping Chia Sep 19 '22 at 02:48
  • 1
    @PingChia I thought Netbeans ceased support for C++ after C++14. Are they now supporting it again? – user997112 Mar 01 '23 at 03:24
  • Dear @user997112, though NetBeans 15 is poor on code assistance for C++20, the C++20 capability is provided by g++12 (in my case). I googled a little and found no information about Apache supporting new C++ on NetBeans, but https://netbeans.apache.org/kb/docs/cnd/ still has related info. – Ping Chia Mar 03 '23 at 02:06
  • 1
    @PingChia Hi. Will the intellisense work? Or just compilation within IDE? – user997112 Mar 03 '23 at 14:25
  • Dear @user997112, NetBeans 15 cannot figure out newer C++ features (Intellisense-wise), but older C++ grammar seems OK. I can compile C++20 project within NetBeans 15 IDE. – Ping Chia Mar 06 '23 at 07:51
  • 1
    @PingChia is there no way the intellisense can "piggy back" off the GCC tokeniser? Then Netbeans would never need to be updated, it would automatically update as the GCC is updated? – user997112 Mar 06 '23 at 10:55
  • Dear @user997112, that is a brilliant idea! I would suggest to all IDE development teams and any other data processing engine that depends on other standards to adopt this method. – Ping Chia Mar 07 '23 at 00:44