问题
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:
- Extracted
gd-latest-win32.zip
toc:\users\johndoe\cpp\libgd
. - Defined
c:\users\johndoe\cpp\libgd\lib
als additional library dir (global VC++ setting) - Defined
c:\users\johndoe\cpp\libgd\include
as additional includes dir (global VC++ setting) - Defined
c:\users\johndoe\cpp\libgd\include\lib\bgd.lib
as additional linker\input dependency (project setting) - I even added
#pragma comment(lib, "libgd.lib")
into mycodecreate.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:
- Running on Linux/g++, everything works fine, no warnings with
-pedantic -ansi -wAll
. The program does its job an generates some barcodes. - 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
- I just downloaded
- 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