How to use/link gdLibrary (libgd) with MS Visual C++ (e.g. 2008 Express Edition)? Getting LNK2019 errors

若如初见. 提交于 2019-12-12 00:38:26

问题


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 :-(

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/2215549/how-to-use-link-gdlibrary-libgd-with-ms-visual-c-e-g-2008-express-edition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!