Wednesday, March 28, 2007

Rough Waters With NetBeans/C++ IDE

Not a good rapport when your new favorite IDE begins to misbehave! I'm enchanted about NetBeans 5.5 and its C/C++ Development Pack that I'm willing to stick it out until I'm sure there's no solution for this problem. And the problem is this error you get when you try to build your Windows programs:

undefined reference to `_GetStockObject@4'
undefined reference to `_PlaySoundA@12'

Actually, the errors are not the IDE or development pack's problems, per se. The combo depends on Cygwin utilities - gcc, g++, make, and gdb - to compile, debug, and build programs. The code compiles just fine; it's the linker that doesn't seem to find header or implementation files required for the methods. For example, the GetStockObject() function is defined in wingdi.h, which is in the same location as other header files the program requires - but for some reason it's not seen. I don't know where the linker is looking for the files/libraries it needs.
Enter the world of DLLs - isn't there a GDI32.dll already on the system that has the same functions defined? I'd think linking would find this library and use it. Apparently it doesn't.
On a flip side, I took the exact code and threw it in Dev-C++, and it did a little better: it didn't produce the first error but it too couldn't find the PlaySoundA() function. Commenting that line out allows the program to run. Is it's library and includes more put together?
But this highlights a problem programmers have to deal with everyday - if you want to program for Windows, you better use Microsoft's tools. Sure enough, when I slap the code into MS Visual C++ 6.0, it builds without complaint. Sinister ... but I won't blame them for the issue at large.
I'm sure there's a solution out there. Google isn't helping much - lots of such problems reported but no solution at all. There's still hope though - I have another [unpolluted] installation of this development environment that I'll try. Hopefully this sheds a little light on this common issue.
I'm really hoping the NetBeans team would just 'nativize' all tools required to run the C/C++ development pack in the NetBeans IDE. At this point, I don't know exactly who to blame. Perhaps there's forums or FAQs I just haven't come across, or documentation I should have read ...