views:

174

answers:

2

Hi all,

I have to use the gdLibrary (http://www.libgd.org) in a C++ App on MS Windows XP Prof. SP3 32bit - and I'm trying and googleing for two days now without success. Does anyone of you use libgd with MS VC++ 200x EE?

My problem: It has to to compile with MS Visual C++ (e.g. the 2008 Express Edition - fixed 3rd party condition)... but currently the linker crashes, with 11 of the following LNK2019 errors:

Linking... codereate.obj : error LNK2019: An undefined external symbol "_gdImageDestroy" was found in "public: virtual __thiscall CodeCreate::~CodeCreate(void)"

The other smybols are _gdImageColorExact, _gdImageCopyResized and some other gd-functions. It seems that the VC++ linker does not work correctly with the bgd.lib provided by the package I downloaded from http://www.libgd.org/releases/gd-latest-win32.zip.

What I did/tried:

  1. Extracted gd-latest-win32.zip to c:\users\johndoe\cpp\libgd.
  2. Defined c:\users\johndoe\cpp\libgd\lib als additional library dir (global VC++ setting)
  3. Defined c:\users\johndoe\cpp\libgd\include as additional includes dir (global VC++ setting)
  4. Defined c:\users\johndoe\cpp\libgd\include\lib\bgd.lib as additional linker\input dependency (project setting)
  5. I even added #pragma comment(lib, "libgd.lib") into my codecreate.h to be on the save side.

Any suggestions? What am I doing wrong (e.g. have I forget to install something)? Is there any "trick" to get a VC++ 2008 compatible bgd.lib?

Additional notes:

  1. Running on Linux/g++, everything works fine, no warnings with -pedantic -ansi -wAll. The program does its job an generates some barcodes.
  2. It works when using DevC++ for Win32. Therefore it is no Windows issue, "just" a VC++ issue. For DevC++ I did:
    • I just downloaded http://www.libgd.org/releases/gd-latest-win32.zip,
    • extracted it to c:\users\johndoe\cpp\libgd
    • added c:\users\johndoe\cpp\libgd\lib\bgd.lib as additional obbject in the linker-projects settings.
    • defined c:\users\johndoe\cpp\libgd\lib als additional library dir,
    • defined c:\users\johndoe\cpp\libgd\include as additional includes dir
    • happy about some barcode stuff
  3. If I can't get It working, I'm really in trouble... becoming really desperate right now :-(
A: 

Did you put NODLL definition in your project? If you did that, you should use bgd_a.lib instead. And you also need to make sure you have defined WIN32.

I tried to create a simple project with latest release and it does linked success. If I add NODLL without changing tot bgd_a then I get the same error message.

Francis
thank god someone answers! :-) Im really new to VC++ (coming from Linux) - I don't think I put the "NODLL" definition into it - where is the place to look? However - I tried "bgd_a.lib" right now... but it does not seem to work, same errors.Maybe I did an error during project creation? I just created a new, empty project, added my *.cpp and *.h files via "right click\Add...->Existing". Thank you, thank you, thank you!
Georg
Right-click on project and select Property, then check C/C++ -> Preprocessor -> Preprocessor Definitions. Default projects should contain something like WIN32;_DEBUG in debug builds.I think maybe you can start by trying to minimize files you added, for example a simple main() with only gdImageDestroy(NULL) to see if that works for linking.
Francis
Oh, you created from "Empty Project"? Then I think you need to add WIN32 definition! I tried to remove WIN32 and then get same error message as yours
Francis
Ok, there were no definitions in there - don't know why. Setting WIN32;_DEBUG brought other errors (good sign!). Therefore I just created a new project (this time a "console application" one), kicked out all predefined files added my ones, set bgd.lib as dependency... and IT COMPILES!! OMG!However: My app crahes directly from start. But I think I simply have to change some lines of code as described under <http://www.libgd.org/FAQ#Why_does_bgd.dll_crash_with_my_C_program.3F> to get it working.
Georg
ohh.. you posted as I was typing. Yes, it seems that it is about the definition. WTH MS though when doing this? And maybe gdLibrary should care about [underscore]WIN32 instead of WIN32 cause it is always there by definition. All I have to do now is to care about the crash. I think http://www.libgd.org/FAQ#Why_does_bgd.dll_crash_with_my_C_program.3F is the key... but that would be another question ;-). To cut a long story short: YOU SAVED MY AS*! Thank you man. :-)
Georg
A: 

Check if you have defined preprocessor macro BGDWIN32 as it is required by libgd in order to compile client code with Visual C++.

Go to project properties, then C/C++ -> Preprocessor -> Preprocessor Definitions

and add BGDWIN32

mloskot