9

In Tools > Options > C/C++ > Other, there is no option for C++17 as the default standard.

How do you compile code that requires C++17?

skomisa
  • 16,436
  • 7
  • 61
  • 102
BrainRenticus
  • 215
  • 3
  • 6

2 Answers2

14

Updated 3/28/21 for NetBeans 12, as documented at the end of this answer.

The C++17 standard was published over a year after NetBeans 8.2 was released, so C++17 is not available as an option in the standard release of 8.2.

However, NetBeans Bug Report Bug 271136 - Support C++17 standard addressed this deficiency, and if you download and install any of the most recent nightly builds of NetBeans 8.2 from 2018 the issue is resolved; C++17 is available as an option when creating a C++ project:

selectCpp17

If you then select {project} > Properties > Build > C++ Compiler you can verify that the C++17 standard is being used:

projectProperties

Notes:

  • When you create subsequent C++ projects, the project wizard will continue to use the C++17 standard by default, so it becomes "the default standard" unless/until you select an alternative.
  • Using a nightly build of NetBeans 8.2 instead of the standard release is also preferable because it contains many unrelated bug fixes.
  • An even better alternative (if it is possible for you) is to download and install the latest release of NetBeans, Apache NetBeans 11.2 which also provides C++17 as an option.
  • If you install a nightly build of NetBeans 8.2, or NetBeans 11.2, your existing installation of NetBeans 8.x will not be touched, so you can safely revert if necessary.

Updated 1/21/20 and 1/22/20:

These are the steps needed to make C++17 available on NetBeans 11.2:

  • Opening the project wizard using File > New Project... shows that C/C++ projects cannot be created by default.
  • Select Tools > Plugins > Settings then click the Add button.
  • In the Update Customizer Center screen, set Name to NBDevDarkThemes and URL to http://bits.netbeans.org/dev/nbms-and-javadoc/lastSuccessfulBuild/artifact/nbbuild/nbms/updates.xml.gz and click OK.
  • Ensure that only the entry for NbDevDarkBeans on the Settings tab is checked.
  • Install the C/C++ plugin by clicking the Available Plugins tab, then checking the entry for C/C++. The version for that plugin should be 1.31.5.1. Click the Install button.
  • After the plugin has been installed, click the Installed Plugins tab, check the Show Details checkbox and scroll down to verify that the C/C++ plugin is installed and Active: CppPlugin
  • Go to Tools > Options > C/C++ >, click the Build Tools tab and configure your external C/C++ environment as required. For example: CppOptions
  • Now go to File > New Project... and you should be able to select C/C++ > C/C++ Application.
  • Click Next >. On the Project Name and Location screen you should now be able to select C++17 for the standard: NewCppProject

Updated 3/28/21 for NetBeans releases 12.x:

Bad news: NetBeans no longer officially supports C++! See the definitive response from Geertjan Welenga, leader of the NetBeans Team, dated 3/25/21 in response to the recent bug report NETBEANS-5501 C++17 no longer available:

*At the moment, NetBeans doesn't support C/C++, the plugins you were/are using from 8.2 are not really officially supported, though work on this is ongoing here, with an end goal to having it officially part of NetBeans, though that will take a while:

https://lists.apache.org/thread.html/r4ac84633554ce80d99b0710e7a803ce1dc322680c914b18058876b51%40%3Cdev.netbeans.apache.org%3E

You're welcome to join in with the discussions on dev above.*

That said, there is an unofficial workaround, as detailed in bug report NETBEANS-4452 The Plugin Installer found problem timeout of loading C/C++ Remote Development API... while install the following plugins: C++. That is:

  • Download JDK 8 (if necessary).
  • Temporarily set the JDK NetBeans 12 uses to JDK 8 by editing netbeans.conf, then restart NetBeans.
  • Install the relevant C/C++ plugins.
  • Reset the JDK NetBeans 12 uses to the one you were using originally - presumably to JDK 14 for most users - by editing netbeans.conf, then restarting NetBeans.
  • C++ 17 should then be available on NetBeans 12, on the clear understanding that it is not officially supported.
skomisa
  • 16,436
  • 7
  • 61
  • 102
  • I installed 11.2 and it doesn't have c++17 as an option. – BrainRenticus Jan 21 '20 at 20:07
  • 1
    My bad, and my apologies for my poor wording. What I meant to state was that with 11.2, while you need to enable C/C++ functionality using the plugin manager, once that it done C++17 will be available as an option automatically. See this note on [NetBeans 11.2 Features](https://netbeans.apache.org/download/nb112/index.html) _"go to the Plugin Manager, enable the NetBeans IDE 8.2 Update Center, which lets you install the NetBeans IDE 8.2 modules providing C and C++ features."_ – skomisa Jan 21 '20 at 20:49
  • I added the C/C++ plugin already, i used [this guide](http://jlavelle.uk/pfw/netbeans-ide/how-to-add-the-missing-plugins/). – BrainRenticus Jan 21 '20 at 21:06
  • 1
    OK. I definitely have C++17 available to me on NB 11.2. Later today I will update my answer with the specific steps to take on 11.2 so that C++17 is available as an option. – skomisa Jan 21 '20 at 21:36
  • 1
    @BrainRenticus [1] I have updated my answer to detail the steps needed to be able to specify the C/C++17 standard on NetBeans 11.2. [2] I did this on Windows 10, but the process should be very similar on other platforms. [3] The approach I took is completely different to the one you linked to, but it worked for me. – skomisa Jan 22 '20 at 03:53
  • I have the plugin and theres nothing in compiler settings that needs adjusted. I used the steps in the link i provided because the C/C++ plugin wasn't listed as an available plugin when i tried to download it. After following those steps i was able to see it in the list and install it. Could this be the problem? Shouldn't i have been able to see it in the available plugins list without the extra steps? I can still make projects but only up to C++14. – BrainRenticus Jan 22 '20 at 04:40
  • 1
    [1] OK. It's as though you have exactly the same problem you had on NetBeans 8.2, right? [2] Perhaps you have an older version of the C/C++ plugin? Can you confirm that you have the version of the C/C++ plugin, as shown in the screen shot above for NB 11.2? (That is: _Source: NBDevDarkThemes, Version: 1.31.5.1_) [3] At the moment the only immediate solution I can think of is to download/install NB 8.2 from the nightly build, as mentioned in my answer above. That should have C/C++ (including C++17) pre-configured, and it won't impact any of your other NetBeans installations. – skomisa Jan 22 '20 at 06:13
  • 1
    I have version 1.30.6.1, i cant find 1.31.5.1 or a way to update the version i have. I uninstalled the C/C++ plugin, removed the Update Center i added and restarted Netbeans. The plugin that is listed by the original Update Centers is still version 1.30.6.1. – BrainRenticus Jan 22 '20 at 20:17
  • 1
    @BrainRenticus OK. You need version 1.31.5.1 of the C/C++ plugin to get C++17. I have updated my answer to specify how to do that, by adding a new *Update Center* entry on the **Tools > Plugins > Settings** tab. If you check only the new entry added on the list of *Update Centers*, then go to the **Available Plugins** tab, you should see the newer version (1.31.5.1) of the C/C++ plugin. – skomisa Jan 22 '20 at 21:46
  • C++17 is available now! Thanks for your help. – BrainRenticus Jan 23 '20 at 18:31
  • 1
    OK. I had changed your question title to refer to "NetBeans 8.x" the other day. That made sense at the time, but I will now revert it back to what you had since NetBeans versions 8.x and 11.x are both relevant. – skomisa Jan 23 '20 at 19:12
  • Thanks for the answer. I upgraded my C++ plugin following the directions. Another way of to set the C++ dialect is using "Additional Options" in the project settings for C++ compiler. Leave the dialect selection at default and put the dialect in the Additional Options: -std=c++2a – rm1948 Oct 09 '20 at 21:05
  • This seems to have broken in NetBeans 12.3 – marczellm Mar 22 '21 at 13:11
  • According to https://netbeans.apache.org/about/oracle-transition.html the old plugin portal servers have been shut down. – marczellm Mar 22 '21 at 13:26
  • 1
    @marczellm Thanks for the information. I have updated my answer with an alternative approach for NetBeans 12.x releases. – skomisa Mar 28 '21 at 16:29
  • @skomisa Thanks for your post. I installed 11.2, C++ was already in the list of available updates. I installed this but it failed right at the end of the install. I went back, added NBDarkThemes and the URL in your post, only that ticked but there's no available plugins. The lists are empty. I just want Netbeans + C++17, i'm not bothered about anything else. Can you help? – user997112 Mar 27 '22 at 02:12
  • @user997112 Unfortunately it looks like the download center URL I gave in my answer `http://bits.netbeans.org/dev/nbms-and-javadoc/lastSuccessfulBuild/artifact/nbbuild/nbms/updates.xml.gz` is no longer valid. And Since NetBeans doesn't _officially_ support C++ right now, you can't even raise a bug report. That said, I recall seeing a helpful comment to a fairly recent [NetBeans] question on SO about an unrelated plugin download not working - apparently someone created a new URL for downloading plugins, though I can't search for it right now (and that question may have been closed anyway).... – skomisa Mar 27 '22 at 05:08
  • ....If you locate that comment, just try their URL instead of the one in the answer above. If not, it might be worth creating a new SO question on this. I have updated the question above a couple of times, but it is unwieldy, and now out of date. The other alternative I was going to suggest if you were desperate was to download a 2018 nightly build of 8.2 which provides C++ 17 out of the box, but the URL for doing that in my answer also no longer works! – skomisa Mar 27 '22 at 05:14
  • @user997112 I misled you in my previous comments. Details on alternative URLs were given [in this helpful answer by Joachim Rohde](https://stackoverflow.com/a/71320872/2985643). I have no idea if that will help you, but give it a go. If not, then I suggest you create a new question because your problem is certainly on topic, and of general interest. The [answer from DMitry above](https://stackoverflow.com/a/66832862/2985643) also provides a URL you can try. – skomisa Mar 27 '22 at 05:28
4

The accepted answer completely valid, but the old plugins repository was shut down, and oracle now redirects all links to their infrastructure to the apache site. It means that we can now download plugins only provided by apache. To add support for C++ 17 to NetBeans 11 (was tested only on 11.0, but some reported that it worked on 12.3, see the comments), you need to do the following

  1. Manually add plugins of the CND module that provides such support. The version of the plugins should be more than 1.31.5.1
  2. Ensure that NetBeans uses JDK8 because old plugins required a upack200 module. It's unavailable, for example, in JDK14.

Steps to install it manually

  1. I downloaded all plugins (NBM files) you need for C++17 support. You can download it here. Beare in mind that the pack was tested only with 11.00 NetBeans. Please, use 11.0 NetBeans.
  2. Then you need to unpack the archive to a folder
  3. Start NetBeans, go-to Tools -> Plugins -> Downloaded.
  4. Click Add Plugins and select all plugins in the archive. Check that you have 64 plugins for installation. Why you need so many plugins? Because the C++ plugin depends on other plugins. So you need to provide the newer versions. enter image description here
  5. Click install. There will be a warning that additional plugins will be installed: enter image description here
  6. After installation, go to the Installed tab, check Show details option and find the C/C++ Plugin. Verify that the version is 1.31.5.1: enter image description here

Automatic installation

The truth is the nightly builds repository was not completely shutdown. You need to know the exact IP address for accessing it. So you could use all the steps from the accepted answer but instead of the link

http://bits.netbeans.org/dev/nbms-and-javadoc/lastSuccessfulBuild/artifact/nbbuild/nbms/updates.xml.gz

you should use:

http://137.254.56.27/dev/nbms-and-javadoc/lastSuccessfulBuild/artifact/nbbuild/nbms/updates.xml.gz

But oracle can restrict access to it at any moment. And also, ensure that your NetBeans runs on JDK8 (upack200 issue).

NetBeans 8.2 Dev Build with C++17 support

If you are looking for old 8.2 release with C++17 support here the last dev build (20180420) from oracle. It runs only on JDK 1.8

Dmitry.M
  • 2,833
  • 1
  • 17
  • 30
  • This almost got me excited, but did not work. I installed NetBeans 12.3 on My Ubuntu 20.04 and downloaded the bundle. When I tried to install, it would not install anything and I get this message: Some plugins require plugin org.netbeans.libs.clank to be installed. The plugin org.netbeans.libs.clank is requested in version 0.1. The following plugin is affected:       C/C++ ... Some plugins not installed to avoid potential installation problems. Any thoughts how to fix that??? – Nikita Visnevski Apr 22 '21 at 23:38
  • @NikitaVisnevski, currently (2021 and since 12.0) NetBeans community is working hard to provide C++ support to NetBeans, so there could be incompatibilities with the old C++ plugins. I tested my pack only with 11.0 NetBeans. Beare in mind that the pack was tested only with 11.00 NetBeans. Please, use 11.0 NetBeans. I updated the answer, added info about 11.0, and removed 12. and 13 versions. – Dmitry.M Apr 23 '21 at 08:13
  • Just to update, I did manage to get it to work in 12.3 after all. There was something wrong with the way I was importing the downloaded plugins and after several attempts I was able to get it all to work. The key is to have 64 plugins in the list. My list repeatedly showed 61 and was dropping 3 plugins for some reason. I had to re-upload the plugins and after list finally showed 64, it all worked. Works quite beautifully by the way. Thank you. – Nikita Visnevski Apr 23 '21 at 12:17
  • 1
    Anybody was able to replicate this process on MacOS? I cannot. It complains about missing plugins like org.netbeans.modules.git.remote, .remote.cli, .mercurial.remote, etc. It also will not let me get any updates giving some certificate security errors. Juts wondering if anybody was more successful at it than me? Thanks – Nikita Visnevski May 18 '21 at 16:23