Development of C ++ in netbeans on Windows and solutions to common problems

Source: Internet
Author: User
Tags netbeans gdb debugger

When writing this article, the latest version of netbeans is 6.8.

If you have not installed netbeans IDE, go to the http://www.netbeans.org and download an IDE version that contains the latest C/C ++ support.

If you have installed netbeans ide but do not have C/C ++ support, complete these steps to add C/C ++ support to the IDE. Select Tools> plug-ins from the main menu ". In the plug-in dialog box, click the available plug-ins tab and scroll to the C/C ++ category. Select the "C/C ++" check box. Click Install ".

On Windows, netbeans ide does not include C/C ++ compilers by default. Therefore, you must manually install the C/C ++ compiler, make utility, and gdb debugger.

Official C/C ++ configuration method http://www.netbeans.org/community/releases/68/cpp-setup-instructions_zh_CN.html

 

On Windows, the netbeans C/C ++ module can be used with the cygwin compiler and the mingw compiler.

- Cygwin compilers and tools
- Mingw compilers and tools

Because cygwin is used on Windows and Linux, the installation is complicated. Therefore, we use mingw as an example.

 

Mingw compilers and tools

 

Software or resources Tested version Description
Gcc 3.4.5 Mingw C Compiler
G ++ 3.4.5 Mingw C ++ Compiler
GDB 6.8 Mingw GNU Debugger
Make 3.79.1 MsysMakeUtilities
Please note that mingw make is not supported

  1. Use an account with the "Computer Administrator" permission to log on to Windows.
  2. Download the self-extracting installer from the howto install the mingw (GCC) compiler suite on mingw.org or directly from this MinGW-5.1.4.exe link for convenience.
  3. Run the MinGW-5.1.4.exe installer in windows.
  4. In the mingw installer, accept the default settings until it is transferred to the "choose components" page.
  5. On the "choose components" Page, select "G ++ compiler ". The GCC compiler is automatically included in the installation, so the compiler is not an optional component.
  6. Do not select mingw make, because you need to use msys make, this component will be downloaded separately. Click "Next ".
  7. If possible, use the defaultC:/mingwAs the target folder, to minimize possible problems with compilers in other locations.
  8. Click "Install" to install mingw, and then click "Next" and "finish ".
  9. According to the Environment Settings (Environment Settings) in the mingw wiki, SetC:/mingw/binDirectory to the PATH variable.
  10. See msys installation instructions in mingw msys wiki. You only need to install the msys 1.0 file. You do not need to install the dtk or core file mentioned on the wiki page.
  11. For convenience, you can directly download from this MSYS-1.0.10.exe link.
  12. When installing msys, make sure that you are using a Windows account with the "Computer Administrator" permission. If you use a user account with limited permissions to install msys, netbeans ide may encounter problems when you attempt to generate and run a project later.
  13. Run the MSYS-1.0.10.exe installer and accept the default settings.
  14. To install the gdb debugger, download it directly from this gdb-6.8-mingw-3.tar.bz2 link. You must have a Windows zip utility (such as gzip, 7-zip, or WinZip) to decompress the gdb archive file.
  15. Extract gdb-6.8-mingw-3.tar.bz2C:/mingwDirectory, so that the gdb executable file will be installedC:/mingw/binDirectory.

After the installation is complete, use the netbeans --> tool --> Option --> C ++ to find that netbeans will automatically read the mingw configuration. Note the make command: C: /msys/1.0/bin/make.exe

 

Create a test program:

/* <Br/> * file: Main. CPP <br/> * Author: Vicky <br/> * Email: eclipser@163.com <br/> */</P> <p> # include <iostream> </P> <p> // using namespace STD; </P> <p> int add (int x, int y) {<br/> return X + Y; <br/>}</P> <p> int main () {<br/> STD: cout <"helloworld/N"; <br/> STD :: cout <add (1, 2) <"/N"; <br/> int A = 0; <br/> int B = 0; <br/> STD :: cout <"enter a number! /N "; <br/> STD: CIN> A; <br/> STD: cout <" enter another number! /N "; <br/> STD: CIN> B; <br/> STD: cout <add (a, B) <STD: Endl; <br/> return 0; <br/>}< br/>

 

Run: a familiar interface appears.

 

Appendix:

1. if you want to apply the netbeans Console window without using the command window in windows, right-click the project and choose Properties> RUN> console type, the default value is the command window in the default Windows system. We should use the output window. Now, the C ++ console has changed.

2. chinese garbled characters occur during compilation: this is because the default character format of netbeans is "UTF-8", while C ++ only supports 2 encoding formats, "GBK" and "XXX (forgot) ", so the same can be done: Right-click the project --> properties --> General --> encoding --> GBK. in addition, you need to restart netbeans to solve Chinese Garbled text!

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.