天天看點

MinGW平台 openjpeg-2.1.0 靜态編譯後未定義引用的解決方法

undefined reference to __imp_opj_xxx
keyword:
   ffmpeg,openjpeg,OPJ_EXPORTS,OPJ_STATIC,opj_version,__imp_opj

出錯原因: 
    1. __declspec(dllexport) / __declspec(dllimport)
    2. __stdcall

解決方法:
openjpeg-2.1.0-modify.to.static.patch

--- src/lib/openjp2/openjpeg.h.orig	2014-04-29 20:58:10 +0800
+++ src/lib/openjp2/openjpeg.h	2016-03-26 01:07:32 +0800
@@ -80,14 +80,14 @@
 /* http://gcc.gnu.org/wiki/Visibility */
 #if __GNUC__ >= 4
 #define OPJ_API    __attribute__ ((visibility ("default")))
-#define OPJ_LOCAL  __attribute__ ((visibility ("hidden")))
+#define OPJ_LOCAL  __attribute__ ((visibility ("default")))
 #else
 #define OPJ_API
 #define OPJ_LOCAL
 #endif
 #define OPJ_CALLCONV
 #else
-#define OPJ_CALLCONV __stdcall
+#define OPJ_CALLCONV 
 /*
 The following ifdef block is the standard way of creating macros which make exporting 
 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
@@ -97,9 +97,9 @@
 defined with this macro as being exported.
 */
 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
-#define OPJ_API __declspec(dllexport)
+#define OPJ_API __attribute__ ((visibility ("default")))
 #else
-#define OPJ_API __declspec(dllimport)
+#define OPJ_API 
 #endif /* OPJ_EXPORTS */
 #endif /* !OPJ_STATIC || !_WIN32 */
 
--- src/lib/openjp3d/openjp3d.h.orig	2014-04-29 20:58:10 +0800
+++ src/lib/openjp3d/openjp3d.h	2016-03-26 00:08:35 +0800
@@ -64,9 +64,9 @@
 defined with this macro as being exported.
 */
 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
-#define OPJ_API __declspec(dllexport)
+#define OPJ_API __attribute__((visibility ("default")))
 #else
-#define OPJ_API __declspec(dllimport)
+#define OPJ_API 
 #endif /* OPJ_EXPORTS */
 #endif /* !OPJ_STATIC || !WIN32 */
 
--- src/lib/openmj2/openjpeg.h.orig	2014-04-29 20:58:10 +0800
+++ src/lib/openmj2/openjpeg.h	2016-03-26 00:09:40 +0800
@@ -66,9 +66,9 @@
 defined with this macro as being exported.
 */
 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
-#define OPJ_API __declspec(dllexport)
+#define OPJ_API __attribute__((visibility ("default")))
 #else
-#define OPJ_API __declspec(dllimport)
+#define OPJ_API 
 #endif /* OPJ_EXPORTS */
 #endif /* !OPJ_STATIC || !_WIN32 */
 
--- thirdparty/include/zconf.h.orig	2014-04-29 20:58:10 +0800
+++ thirdparty/include/zconf.h	2016-03-25 11:15:49 +0800
@@ -277,9 +277,9 @@
 #  ifdef ZLIB_DLL
 #    if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
 #      ifdef ZLIB_INTERNAL
-#        define ZEXTERN extern __declspec(dllexport)
+#        define ZEXTERN extern __attribute__((visibility ("default")))
 #      else
-#        define ZEXTERN extern __declspec(dllimport)
+#        define ZEXTERN extern
 #      endif
 #    endif
 #  endif  /* ZLIB_DLL */
@@ -306,11 +306,11 @@
 #if defined (__BEOS__)
 #  ifdef ZLIB_DLL
 #    ifdef ZLIB_INTERNAL
-#      define ZEXPORT   __declspec(dllexport)
-#      define ZEXPORTVA __declspec(dllexport)
+#      define ZEXPORT   __attribute__((visibility ("default")))
+#      define ZEXPORTVA __attribute__((visibility ("default")))
 #    else
-#      define ZEXPORT   __declspec(dllimport)
-#      define ZEXPORTVA __declspec(dllimport)
+#      define ZEXPORT
+#      define ZEXPORTVA
 #    endif
 #  endif
 #endif
--- thirdparty/liblcms2/include/lcms2.h.orig	2016-03-26 00:00:04 +0800
+++ thirdparty/liblcms2/include/lcms2.h	2016-03-25 23:59:52 +0800
@@ -195,14 +195,14 @@
 #ifdef CMS_IS_WINDOWS_
 #  if defined(CMS_DLL) || defined(CMS_DLL_BUILD)
 #     ifdef __BORLANDC__
-#        define CMSEXPORT    __stdcall _export
+#        define CMSEXPORT    __attribute__((visibility ("default")))
 #        define CMSAPI
 #     else
 #        define CMSEXPORT    _stdcall
 #        ifdef CMS_DLL_BUILD
-#            define CMSAPI   __declspec(dllexport)
+#            define CMSAPI   __attribute__((visibility ("default")))
 #        else
-#           define CMSAPI    __declspec(dllimport)
+#           define CMSAPI
 #       endif
 #     endif
 #  else
--- thirdparty/libpng/pngconf.h.orig	2014-04-29 20:58:10 +0800
+++ thirdparty/libpng/pngconf.h	2016-03-25 11:15:20 +0800
@@ -1315,9 +1315,9 @@
 
 #    ifndef PNG_IMPEXP
 #      ifdef PNG_BUILD_DLL
-#        define PNG_IMPEXP __declspec(dllexport)
+#        define PNG_IMPEXP __attribute__((visibility ("default")))
 #      else
-#        define PNG_IMPEXP __declspec(dllimport)
+#        define PNG_IMPEXP
 #      endif
 #    endif
 #  endif  /* PNG_IMPEXP */