Roy A. Triesscheijn’s Weblog

My programming world

Configuring Cygwin C/C++ compiler for Netbeans 6.5 (under Windows)

Posted by royalexander on Friday 20 March, 2009

Today I tried setting up Netbeans as a C IDE, it has built in support for C, but unfortunately enough you have to manually configure a compiler so that you can actually debug / build your C/C++ programs.

 

Fortunately there is this helpful page at Netbeans.org to help you install Cygwin, a very popular UNIX/Windows C/C++ compiler. However, this helpful page isn’t as helpful as I’d hope at all! It will point you in the right direction to download Cygwin, and will tell you what packages to select for download, it will even tell you to set up your PATH environment variable for Cygwin, but it will assume Netbeans auto detects the correct settings, which it unfortunately doesn’t do. (Well at least at my pc, and I’ve seen a few threads with the same problems around).

So here is my attempt at a more complete overview on installing Cygwin for Netbeans 6.5.

Go to http://www.cygwin.com/setup.exe and download the small setup program. Run it (if your using Vista, set the compatibility options to XP SP2, and run it as administrator). Follow the pretty standard steps until you get to choose the installation packages. If you thought just pressing next would install the most common Cygwin apps, like the compiler (gcc.exe) and the make implementation, unfortunately Cygwin, is not just a C/C++ compiler, it even includes a java compiler, games, documentation, text editors etc. . Ok so just install everything, well that will install the compiler etc., but also 3GB of (for us) useless data. So don’t make the same mistake I did there. We are going to search for the few packages that we actually need. According to the Netbeans.org these are:

select gcc-core: C compiler, gcc-g++: C++ compiler, gdb: The GNU Debugger, and make: the GNU version of the ‘make’ utility.

Unfortunately these aren’t easy to find. For example there is no core package directly visible (we do have base and development though).  It took me a while but I think I’ve nailed it down. Select the following packages by clicking the weird “refresh” icon next to them until it says install:

-The entire base package
-In the development package select:
–binutils
–gcc core
–gcc g++
–gcc g77
–gcc mingw core
–gcc mingw g++
–gcc mingw g77
–gdb
–make
–mingw runtime

(note I’m not sure about the mingw packages, this seems to be a seperate C compiler but it doesn’t seem to harm)

After that go to windows configuration screen->advanced->environment variables. And add "C:\Cygwin\Bin” to the PATH variables (or wherever you have located your Cygwin\bin folder, (make sure to separate it from the last one with a ‘;’).

Start Netbeans, navigate to tools->options->C/C++. Check to see if Cygwin is in the list on the left panel. Select it, and then fill in the options as following: (I assume that you’ve installed it in C:\Cygwin)

Base Director: C:\Cygwin\bin
C compiler C:\Cygwin\bin\gcc.exe
C++ Compiler: C:\Cygwin\bin\g++-3.exe*
Fortran Compiler: C:\Cygwin\bin\g77-3.exe*
Make Command: C:\Cygwin\bin\make.exe
Debugger: C:\Cygwin\bin\gdb.exe

(* marks optional)

Now make a new C project. And add a new main file to it by right clicking the source directory and selecting New->Main C file. There is an odd chance that the include directives will be underlined with red. This is not a problem, as you will see the program will compile and run fine, but you can’t use intellisense this way so we are going to fix it. (First make sure your PATH variable was correctly set!).

Right click on your project and select properties. Go to build->C compiler (or C++ compiler if you are doing C++).  Select the “…” button after Include Directories. And add the “C:\Cygwin\usr\include” directory to the include directories. Save your settings and reload your project. The red lines should’ve disappeared now, leaving you behind with a fully functional C/C++ IDE and compiler in Netbeans. *Yay*!

Art

(I wish someone else would’ve written this before me, so that I wasn’t busy uninstalling a couple of gigabytes of C/C++ tools/compilers/utilities/fonts and text editors!)

79 Responses to “Configuring Cygwin C/C++ compiler for Netbeans 6.5 (under Windows)”

  1. George said

    I followed the instructions on netbeans and had exactly the same issues. your instructions are way better. Maybe they should add a link to this page on the netbeans page. Good job and thanks for sharing your efforts with the rest of the world.

  2. John Derrick said

    thanks dude, I thought i done bad

  3. Josh said

    This works.

  4. marcellus | wolfdart said

    Tks, its worked!

  5. TheRoot said

    Hey, Great! it works! I solve that bit of the problem however, i couldn’t run my programs (can’t click run button or command) in netbeans. i have set the system variables the way you specify. Have you encountered this same problem ? I’m using a 32-bit Vista by the way. Cheers :)

    • Hey TheRoot, hmm that sounds like a strange problem. I haven’t encountered it yet. Are you sure you’ve restarted Netbeans (and your computer?) and that you have created a new clean C project in Netbeans? (or C++ if you where aiming for that one). Also make sure that in the options in Netbeans the compilers etc.. are listed under the C/C++ section.

  6. John Greece said

    Thanks mate, you’ve done some great work. It took me hours to find out what was wrong…
    Really helpful guide!

  7. razz said

    Hi. Can anybody help me? When I try to Run/Build/Debug my application I get this error:

    Running “C:\Programy\cygwin\bin\make.exe -f Makefile CONF=Release” in C:\Documents and Settings\Pavel\Plocha\c\app\Application_1

    /usr/bin/make -f nbproject/Makefile-Release.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory `/cygdrive/c/Documents and Settings/Pavel/Plocha/c/app/Application_1′
    /usr/bin/make -f nbproject/Makefile-Release.mk dist/Release/Cygwin-Windows/application_1.exe
    make[2]: Entering directory `/cygdrive/c/Documents and Settings/Pavel/Plocha/c/app/Application_1′
    mkdir -p build/Release/Cygwin-Windows
    rm -f build/Release/Cygwin-Windows/test.o.d
    gcc.exe -c -O2 -I/cygdrive/C/Programy/cygwin/usr/include -MMD -MP -MF build/Release/Cygwin-Windows/test.o.d -o build/Release/Cygwin-Windows/test.o test.c
    mkdir -p dist/Release/Cygwin-Windows
    gcc.exe -o dist/Release/Cygwin-Windows/application_1 build/Release/Cygwin-Windows/test.o
    /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -luser32
    collect2: ld returned 1 exit status
    make[2]: *** [dist/Release/Cygwin-Windows/application_1.exe] Error 1
    make[2]: Leaving directory `/cygdrive/c/Documents and Settings/Pavel/Plocha/c/app/Application_1′
    make[1]: *** [.build-conf] Error 2
    make[1]: Leaving directory `/cygdrive/c/Documents and Settings/Pavel/Plocha/c/app/Application_1′
    make: *** [.build-impl] Error 2

    Build failed. Exit value 2.

    I installed according to instructions…

    • Hi Razz, it seems there is something wrong with -luser32, try searching for that, unfortunately I have no idea what could cause this problem, does this also occur on a new clean C project?

  8. MakiS said

    axa.. thanks , i just press to download all packages and netbeans find them alone… , ty ;)

  9. kisa14 said

    hiss
    thanks for the tutorial, it really worked for me, but I just have a problem, it build the programs and all of that but when I try to run them this message come

    This application has failed to start because cygwin1.dll was not found
    Re-installing the aplication may fix this problem

    what could I do?? or I have to re-install all the components again?
    just that and thanks!!

    • Hey Kisa14,

      I’ve looked into my Cygwin\bin folder and indeed there is a file called cygwin1.dll located there, can you check if your bin folder has the same file or that it is really missing? You can try to reinstall the cygwin cg and cg++ compilers.

  10. kisa14 said

    Hi,
    Well yes, I just found it there.
    But I kind of solve the problem by other way, I just modified the path, because I haven’t put the ‘-3′ there, now I put it and the program is working xP
    Any way thanks a lot for the tutorial!!! and for answering so soon ^^
    byess

    • kisa14 said

      By the way, the prove program just run and close, I can’t even see it xD (but well the other programs I have from my labs run correctly ^^U)

  11. JOhn said

    Ok where did you find packages ? you just google them??? thanks in advance
    The entire base package
    -In the development package select:
    –binutils
    –gcc core
    –gcc g++
    –gcc g77
    –gcc mingw core
    –gcc mingw g++
    –gcc mingw g77
    –gdb
    –make
    –mingw runtime

  12. Quang said

    Thanks a lot. It worked. ^^

  13. UCSC said

    hey guys its worked …thax a lot

  14. udara said

    i did exactly the same thing mentioned above,but there is no gcc.exe file in folde “bin”.Instead there is a shortcut called gcc.exe.lnk which links to “/etc/alternatives/gcc”.So i choosed gcc-3.exe for c compiler.But when i make a new c project it says ” cannot find include file “. but it works for c++.dont know y?

    • Hey Udara,

      Unfortunately I don’t have an answer to your question, but maybe someone else visiting this website has. I would recommend figuring out if you can remove all the gcc apps and see if it works the second time, maybe you’ve forgot to select an option. (Alternatively you can try repairing the installation and checking if you missed something)

    • Anubhav said

      Hi Udara,

      You could use the following steps(Netbeans 6.5):

      1. Tools->Options->C/C++->Code Assistance->C Compiler->Add.
      2. Add this directory: C:\cygwin\lib\gcc\i686-pc-cygwin\3.4.4\include (Replace C:\cygwin\ with your cygwin home)
      3. Done

      I hope it helps.

      Also I think the following packages are optional with gcc’s core compilers:

      –gcc mingw core
      –gcc mingw g++
      –gcc mingw g77
      –mingw runtime

  15. Pradeek said

    You can find these in the devel package instead of manually searching.

  16. Cris said

    Thank you so much for posting these instructions- I was stumped for 18 straight hours losing my mind trying to get this to work… your instruction here is a life saver- really thanks again :)

  17. jOBr said

    Excelent job man, I had this configuration but I formatted my computer, now I cannot add it to my netbeans, I have the same Udara’s problem.

    i’ll aprecciate any help thk

  18. Milos Grcic said

    thnx mate! it works to me :)

  19. Fata1Diabl0 said

    This is so cool.
    thanks for your help. i really appreciate your effort.
    I’ve been looking for a solution for weeks. thanks to you i can have more fun programming. Thanks a lot dude and may god bless you!
    :)

  20. mizbase said

    Thanks buddy,
    really helped, i think netbean should link your page,
    the help page sucks, regarding the instruction they have given
    thanks a lot

  21. satish said

    hey frds…somebody help me..i followed the same instructions..still i am getting this error..
    ———————————————————————————————
    Running “C:\Program Files\MATLAB\R2007a\bin\win32\gmake.exe -f Makefile CONF=Debug” in C:\SATISH PERSONAL\Application_1

    /cygdrive/c/Users/satish/AppData/Local/Temp/make38802.sh: line 2: syntax error: unexpected end of file
    C:\Program Files\MATLAB\R2007a\bin\win32\gmake.exe: *** [.validate-impl] Error 2

    Build failed. Exit value 2.
    —————————————————————————————————

    what could be the problem?

    • Hey Satish, it looks like the compiler and stuff got installed perfectly but that there is an error in your code. Also your not using the GNU compiler but a special compiler for Matlab so it seems so I’m sorry but I can’t really help you with this error.

  22. joer86 said

    hey could guyz help me? i’ve been encountering an output error with the C++ sample code “welome”. the project builds and debugs fine but when i run it it shows this in DOS…

    “C:/Users/SATEL~1AppData/Loca/Temp/dlight736194469083965267termexec.env: line1: syntaxerror near unexpected token ‘(‘
    C:/Users/SATEL~1AppData/Local/Temp/dlight736194469083965267termexec.env: line1: ‘PATH=/bin:/user/bin::cygdrive/C/Windows/system32:/cygdrive/C/Windows:/cygdrive/C/Windows/System32/Wbem:/cygdrive/C/PROGRA~2/COMMON~1/ULEAD~1/MPEG:/cygdrives/DivX\Share/:/cygdrive/C/Program\Files\(x86)/Quicktime/QTSystem/:/cygdrive/C/cygwin/bin: && export PATH’
    Press [Enter] to close the terminal…”

    the code is very simple w/c is just supposed to output Welcome and this a sample code from Netbeans itself. I followed instructions from Netbeans site and from urs exactly… looks like i should settle for turbo c++… tsk tsk.

  23. Sue said

    Thanks for the steps. But I can’t add the paths to windows configuration screen->advanced->environment variables. Every time I try from “My Computer/Properties”, configuration screen came up for 2 second and disappear. Is it a must to add the path?

  24. Eugene Kovalev said

    Thanks a ton, these really helped.

    I’m just a beginner and I’m trying to learn a little bit of C before I go to college. I installed this program and followed all the instructions but when I try to run this “Hello, World” program:
    #include

    main()
    {
    printf (“Hello, World!”);
    return 0;
    }

    I get the following messages and I have absolutely no clue what they mean, Please Help!

    /usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory `/cygdrive/c/Users/Eugene Kovalev/Briefcase/My Programs/Learning C programming/Learning C’
    /usr/bin/make -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/learning_c.exe
    make[1]: *** [.build-conf] Aborted (core dumped)
    make[1]: Leaving directory `/cygdrive/c/Users/Eugene Kovalev/Briefcase/My Programs/Learning C programming/Learning C’
    make: *** [.build-impl] Error 2
    BUILD FAILED (exit value 2, total time: 6s)

  25. BigBwana said

    I’m having problems, I downloaded and installed using the setup.exe (I used the defaults) from cygwin. It looks like I have everything (even the desk icon) except for the compilers.
    In C:\cygwin, there is everything EXCEPT:

    C compiler C:\Cygwin\bin\gcc.exe
    C++ Compiler: C:\Cygwin\bin\g++-3.exe*
    Fortran Compiler: C:\Cygwin\bin\g77-3.exe*
    Make Command: C:\Cygwin\bin\make.exe
    Debugger: C:\Cygwin\bin\gdb.exe

    Maybe I downloaded from a screwy site, but it was on the list.
    What can I do to finish my instillation?

  26. BigBwana said

    Ok, I think I figured it out – forgot to select the compilers in the dev package – Kinda thought they would be there by default.

  27. Kotushka said

    Thunk you a lot.

    ” Base Director: C:\Cygwin\bin
    C compiler C:\Cygwin\bin\gcc.exe
    C++ Compiler: C:\Cygwin\bin\g++-3.exe*
    Fortran Compiler: C:\Cygwin\bin\g77-3.exe*
    Make Command: C:\Cygwin\bin\make.exe
    Debugger: C:\Cygwin\bin\gdb.exe

    this part was very useful for me. This is not said properly even by the net beans.

  28. KJB said

    Once your C and C++ compilers are installed.

    You should only add include libraries to the project that are different from the standard compiler libraries.
    To add or check standard libraries that are to be included click on Tools->Options and then select C/C++ at the top of the window that appears.
    Now select the Code Assistant tab.
    The top panel has a C and a C++ tab.
    Now start a cygwin command window
    Start->All Programs->Cygwin->Cygwin Bash Shell
    Type or copy this command for the c compiler
    `gcc -print-prog-name=cc1` -v
    where gcc is your C compiler.
    This will give you a list of include libraries that the preprocessor is using. Make your otions window match this list.

    Now the C++ compiler
    `gcc -print-prog-name=cc1plus` -v
    gcc is still the C compiler and not the C++ compiler.
    This will give you a list of include libraries that the preprocessor is using. Make your otions window match this list. Make sure that the C++ tab is selected or you will be updating the C include list.

    Your code assistant now matches your compiler.
    Any additional libraries that you now want to use and are not part of the current project should be added to the project->preferences.

  29. QZip said

    Hey, I tried the NetBeans instructions, but, since they were about as helpful as a knife in the back, I fubared something. When I went into the Environment Variables and changed my path, I DELETED the old path and REPLACED it with “C:\cygwin\bin” when, it seems from your instructions I was just supposed to add that (with a ;) to the END of whatever the hell was there. Now, I have no idea what was there and no way to tell the thing to default back to whatever it was before I screwed it up. If I go into NetBeans, it can’t detect Cygwin. Can you help? I’m running Windows XP Service Pack 3 (if it matters).

    • Hey QZip, that is a really serious problem since the path variable is not only the C(++) path variable but also the commandline, JAVA, .NET PATH variable (and probably much more) I can’t really give you some way to get it back, maybe you can do a system restore. You can’t copy the PATH variables from someone else because not everyone has installed their applications at the same locations. Your best bet to partially get everything working again if system restore fails is to find someone with XP Service Pack 3 and rougly the same software installed, copying their PATH variable to your pc and hoping you both installed most applications at their default locations.

      (I know this all sucks, most modern installers modify the path variable for you, unfortunately Cygwin and especially the Cygwin installer is ‘way odd’.)

      Good luck with restoring your computer, sorry I can’t help you I’m running Vista.

  30. Ricky said

    Thank you a lot, this was so helpful for me.

    Greetings

  31. Bruce said

    Wow, thanks! That was extremely helpful.

  32. Maru said

    Hi, thank you SO much for this, I can’t tell you how many hours I spend trying to get this done!!!! I’m so used to JAVA that whenever some comes to me asking for help with C (I’m a TA on a fundamentals of programming class) I remember that I haven’t done this stuff for my netbeans…

    Does this steps also work on nebeans 6.7?????

    PS: sorry for my english… I’m from South America =)

  33. Arpit said

    Hello:

    I am in a fix. Please suggest me some help. I am building an application and using Cygwin development environment. All compilation is successful but every time at linking stage I get the error 53 !!

    see this -

    (LD) exe/DEBUG/DSP1_p0.dxe exe/DEBUG/DSP1_p1.dxe exe/DEBUG/DSP1_sm.dxe
    “C:\Program Files/Analog Devices/VisualDSP 4.5/linker.exe” -jcs2l -si-revision
    0.5 -T DSP1.ldf -Map ../../Integration/build/exe/DEBUG/DSP1.map.xml -od ../../In
    tegration/build/exe/DEBUG -MDBUILD_TYPE_DEBUG
    make[1]: *** [../../Integration/build/exe/DEBUG/DSP1_p0.dxe] Error 53
    make[1]: Leaving directory `/cygdrive/c/Y050-buildBV/Integration/build’
    make: *** [binaries-all] Error 2

    Please let me know if you require some more info. But since past one week, I am stupidly wasting my time trying solving this issue but still not successful :(

    • Hey Arpit, I have no idea how to fix this issue, best ask it at a forum related to Cygwin C++ compiler. (Maybe the Cygwin website or mailing list?). I’ll leave your comment here so other people might suggest fixes.

    • Arpit said

      Hello Royal:

      I checked with Analog Devices guys today.. they say,

      ” ‘Error 53′ is being reported by cygwin itself. and reports “The network path was not found”. If the error was being reported by VisualDSP++ tools it would be in our standard error format. For a linker failure, the error message would have the form li####: “li” as a prefix meaning it came from the linker and the “####” being the error number that can be used to index help documentation.

      Since the error comes from cygwin we are going to have a limited ability to determine the cause. We can only suggest that you check that the path reported in the error message from cygwin exists and you have proper permission to access it. ”

      So they say its not a linker error basically but a Cygwin path error. Can you suggest me what they mean by network path of Cygwin?

      • Hey Arpit,

        I wouldn’t know what they mean with network path, I mean all your files are on a local drive right? Can you check if “../../Integration/build/exe/DEBUG/DSP1_p0.dxe” is indeed 2 folders up from the working directory?

        • Arpit said

          Hey Royal,

          Yeah. you are right. It is indeed a local drive! so your explanation is perfect – there cannot be a problem with network path, but then what is causing Error 53? Analog Devices people say its not Visual DSP, its Cygwin causing the error..

  34. tom said

    Worked very nicely. Thank you very much Roy.

  35. BA said

    Thanks Roy… that was a real help. I’m way past the thrill of spending fruitless hours to make things work that should be intuitive. You are on the list of people to be reimbursed if I ever get to make money from my current C++ development .

  36. Nate said

    Did my best to follow your instructions, still getting this error when I try to build:

    /usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory `/cygdrive/c/Users/Nathan/Documents/NetBeansProjects/HelloWorldNative’
    /usr/bin/make -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/libHelloWorldNative.dll
    make[2]: Entering directory `/cygdrive/c/Users/Nathan/Documents/NetBeansProjects/HelloWorldNative’
    mkdir -p build/Debug/Cygwin-Windows
    make[2]: mkdir: Command not found
    make[2]: *** [build/Debug/Cygwin-Windows/newmain.o] Error 127
    make[2]: Leaving directory `/cygdrive/c/Users/Nathan/Documents/NetBeansProjects/HelloWorldNative’
    make[1]: *** [.build-conf] Error 2
    make[1]: Leaving directory `/cygdrive/c/Users/Nathan/Documents/NetBeansProjects/HelloWorldNative’
    make: *** [.build-impl] Error 2
    BUILD FAILED (exit value 2, total time: 1s)

    Assistance would be appreciated!

  37. Arpit said

    Hi Royal.

    Finally got rid of that error. Had a tough time tracing that out. Yeah, as i said, you were correct that AD people were incorrect in telling Err 53 being a network path error.

    Interestingly, the project was using a tool MapReader.exe of CadCorp that evaluates linker files. And my machine was not having .netframework installed that caused problem with its initiation and hence at linking stage Visual DSP was unable to commence -> that way, the poor guy Cygwin which was being used had no clue but to show me Error 53 coz of this!!

    Thanks for your help. Am glad after eliminating this 53 from my m/c!!

  38. Koen said

    Quite a neat site you have here, Royal! Not sure what it’s all about though.

  39. dan said

    Thank you very much for your effort.
    I’m from Romania.

    A good day to you.

  40. khosi said

    I am from South Africa. Thank you very much. This article is the ish, each and every step of the configuration is well laid out.

  41. Joey said

    I have followed your unstruction completely but when I enter “C:\Cygwin\bin\gcc.exe” it enters as red and when i open up netbean it tells me

    Could not successfully run the C:\Cygwin\bin\gcc.exe compilerto configure the built-in source file paser.
    Please make sure C:\Cygwin\bin\gcc.exe is in your PATH and restart the ide

    Its tells me that the compiler is missing or invalid…

    Im only new at this so any help would be very much appricated

  42. Arjita said

    This is awesome! I spent so much time trying to figure this out…until I found this post.
    Really helpful and clear. Thanks :)

  43. JKirk said

    This site was useful, but I still seem to have problems.

    I can’t seem to understand what you meant when you described adding the Path. How exactly does one get to the “Windows Configuration Screen” on Vista?

    My compilers seem to have added correctly, but the code I’m trying to work on doesn’t include the appropriate libraries.

    I’m new to NetBeans, so any help would be appreciated.

  44. Vencat said

    Hello there.
    Thanks a lot for this useful tips.
    I followed it to start a C++ application on Netbeans6.7.1 windows and every hello world, or Netbeans samples seem to work fine. But I have troubles when I start to use wstring.
    When I #include and declare a std::wstring, g++ whispers me that wstring is not part of std…
    My paths seem good… I have no clue.
    Any idea ?

    Thanks again.

  45. kibre said

    building is successful but it won’t run…. The system cannot find the path specifiedProcess is started in an external terminal …
    RUN FAILED

    this message appears… any idea ,

  46. The Weba said

    Thanks so much!!! ^_^

  47. Sonal said

    Followed all instructions as above, but still stuck up with this error :(
    Can you please help..
    Error:
    CLEAN SUCCESSFUL (total time: 200ms)

    nbproject/Makefile-Debug.mk:79: .dep.inc: No such file or directory
    make: /bin/sh: Command not found
    make: *** [.depcheck-impl] Error 127
    BUILD FAILED (exit value 2, total time: 187ms)

  48. CodenameA said

    You are GOD!!!
    Your instructions just saved me hours of wasted time and you may also have saved my computer from ending up like this:

    http://www.youtube.com/watch?v=0qKxSf5SNj0&feature=related

    ThX!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>