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.