1. libgd
  2. Untitled project
  3. gd-libgd


Ondřej Surý  committed 444555f

Rework the visibility #ifdef and #define block (fixes #27)

  • Participants
  • Parent commits 36d5f8a
  • Branches master

Comments (10)

  1. Ondřej Surý author

    The NONDLL logic was broken anyway, since it should be declared on Windows for static builds, but it's also defined on all non-WIN32 platforms.

    I guess you are using cmake on Windows, am I correct?

    I would like to clean this up definitely for all platforms.

  2. Pierre Joye

    Yes, cmake on win using VC (9 and 11).

    BGDWIN32 is known yes, but something may have gone wrong, Checking what went wrong and was luckily working before. Double checking your change shows that there is no logical change in this change.

  3. Ondřej Surý author

    I understand it now. Basically just replace the #if !defined(NONDLL) || defined(BUILDING_DLL) line with #ifdef BGDWIN32 should fix the build. I am debugging this over a phone, so I am not able to do the commit.

  4. Ondřej Surý author

    The issue is that the static build on WIN32 was broken before. Could you please send me generated config.h from WIN32? I'll think of some better way of detecting if we are building a library or including the header into an application.

  5. Pierre Joye

    We may need (for now) to build either shared or static using cmake on Windows as as far as I can see it does not rebuild the various objects to create the static library, which makes gd.h definition pointless. Will check that again tomorrow.

  6. Ondřej Surý author

    I have just checked CMakeLists.txt. BGDWIN32 is enough, and the WIN32 build need another #ifdef to build the static library. There are three cases: shared library, static library and header include. Each needs different #defines. Tomorrow it is.

    I'll also add BGDWIN32 to configure.ac in case somebody wants to use autotools on Windows.

  7. Ondřej Surý author

    Win32 should be fixed in last commit, sorry for the breakage. That's the toll for having two build systems :(.

    I cannot test the fix right away since I don't have Win32 jenkins build slave (yet), and I use my home Windows mashine purely for SWTOR :), but I am pretty confident that lack of sleep makes me a better hacker...

Files changed (1)

File src/gd.h

View file
  • Ignore whitespace
 #ifdef __cplusplus
 extern "C" {
    wish to build gd as a static library or by directly including
    the gd sources in a project. */
-#if !defined(WIN32) && !defined(_WIN32_WCE)
+#if !defined(WIN32) && !defined(_WIN32_WCE) && !defined(CYGWIN)
 #define NONDLL 1
 #endif /* WIN32 */
 /* http://gcc.gnu.org/wiki/Visibility */
-#ifdef NONDLL
+#if defined(WIN32) || defined(CYGWIN) || defined(_WIN32_WCE)
+# if !defined(NONDLL) || defined(BUILDING_DLL)
+#  ifdef __GNUC__
+#   define BGD_EXPORT_DATA_PROT __attribute__ ((dllexport))
+#  else
+#   define BGD_EXPORT_DATA_PROT __declspec(dllexport)
+#  endif
+# else
+#  ifdef __GNUC__
+#   define BGD_EXPORT_DATA_PROT __attribute__ ((dllimport))
+#  else
+#   define BGD_EXPORT_DATA_PROT __declspec(dllimport)
+#  endif
+# endif
+# define BGD_DECLARE(rt) BGD_EXPORT_DATA_PROT rt __stdcall
-#  define BGD_DECLARE(rt) __attribute__ ((visibility ("default"))) extern rt
 #  define BGD_EXPORT_DATA_PROT __attribute__ ((visibility ("default")))
 #  define BGD_EXPORT_DATA_IMPL __attribute__ ((visibility ("hidden")))
 # else
-#  define BGD_DECLARE(rt) extern rt
 # endif
-# ifdef BGDWIN32
-#  define BGD_DECLARE(rt) __declspec(dllexport) rt __stdcall
    1. Ondřej Surý author

      This might be the hour talking, but are you sure that it was this commit which broken the win32 build? Because according to the link, it should have been broken before. And it seem to me that BGD_DECLARE is missing only the 'extern' keyword from the previous definition. Only it's construction is little more complicated. But it might be the missing 'extern' causing the problem.

        1. Ondřej Surý author

          Not yet :). My last commit (0e41ffa) should be the right one, but feel free to correct me.

          The three cases should be like this: building DLL -> dllexport building static -> nothing including header from application -> dllimport

-#  define BGD_EXPORT_DATA_PROT __declspec(dllexport) extern
-#  define BGD_EXPORT_DATA_IMPL __declspec(dllexport)
-# else
-#  define BGD_DECLARE(rt) __declspec(dllimport) rt _stdcall
-#  define BGD_EXPORT_DATA_PROT __declspec(dllimport) extern
-#  define BGD_EXPORT_DATA_IMPL __declspec(dllimport)
-# endif /* BGDWIN32 */
-#endif /* NONDLL */
 #ifdef __cplusplus
 	extern "C"