Compiling libgd on WinXP/MinGW/MSYS
| From: | JA Robson | Date: | Mon, 18 Feb 2008 03:08:07 +0000 |
| Subject: | Compiling libgd on WinXP/MinGW/MSYS | ||
| Groups: | php.gd.devel | ||
| Request: | Send a blank email to php-gd-devel+get-367@lists.php.net to get a copy of this message | ||
I have a WinXP machine running MinGW/MSYS, and I was having a tough
time getting libgd to compile. The message "symbol lacks external
linkage" kept popping up. I did some poking around on the Internet and
found that it had something do with the 'dllimport' attribute on
function calls.
http://www.google.com/search?ie=UTF-8&oe=utf-8&q=%22symbol+lacks+external+linkage%22&qt_s=Search&sa=N&tab=gw
I eventually landed here --
http://www.phpman.info/index.php/info/gcc
-- and after some tinkering, made a little hack that worked to get it
to compile. I can't really explain why it works (my notion of vtables
and system handling of library function export/imports is hazy, I'm
afraid), but I thought it might be useful to note for users building
libgd with this particular config. Also, I thought the maintainers may
have a clearer idea about what's going on, and provide a better hack
to accommodate the MinGW environments.
My hack was as follows:
----- Makefile:
DEFS = -DHAVE_CONFIG_H -DMINGW
----- gd.h:
#ifdef MINGW // Declare macros this way...
#define BGD_DECLARE(rt) __declspec(dllexport) rt __stdcall
#define BGD_EXPORT_DATA_PROT __declspec(dllexport) extern
#define BGD_EXPORT_DATA_IMPL __declspec(dllexport)
#else // If not MINGW, then do defines the original way
#ifdef NONDLL
#define BGD_DECLARE(rt) extern rt
#else
#ifdef BGDWIN32
#define BGD_DECLARE(rt) __declspec(dllexport) rt __stdcall
#else
#define BGD_DECLARE(rt) __declspec(dllimport) rt _stdcall
#endif // BGDWIN32
#endif // NONDLL
/* 2.0.20: for actual storage of exported data, functions don't need this,
currently needed only for font pointers */
#ifdef NONDLL
// 2.0.25: bring back extern
#define BGD_EXPORT_DATA_PROT extern
#define BGD_EXPORT_DATA_IMPL
#else
#ifdef BGDWIN32
#define BGD_EXPORT_DATA_PROT __declspec(dllexport) extern
#define BGD_EXPORT_DATA_IMPL __declspec(dllexport)
#else
#define BGD_EXPORT_DATA_PROT __declspec(dllimport) extern
#define BGD_EXPORT_DATA_IMPL __declspec(dllimport)
#endif // BGDWIN32
#endif // NONDLL
#endif // MINGW
Cheers, JA