Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you enable C++17 in Netbeans?

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?

like image 602
BrainRenticus Avatar asked Jan 20 '20 17:01

BrainRenticus


2 Answers

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.
like image 127
skomisa Avatar answered Sep 18 '22 08:09

skomisa


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

like image 42
Dmitry.M Avatar answered Sep 19 '22 08:09

Dmitry.M