[x264-devel] ICL/MSVS: Fix shared library generation and usage

Steven Walters git at videolan.org
Wed Apr 25 00:17:09 CEST 2012


x264 | branch: master | Steven Walters <kemuri9 at gmail.com> | Wed Mar 28 21:15:04 2012 -0400| [35cf912671fddcb3e701bf667a75f77dd8b28264] | committer: Jason Garrett-Glaser

ICL/MSVS: Fix shared library generation and usage
MSVS requires exported variables to be declared with the DATA keyword, and requires that imported variables be declared with dllimport.
This does not fix x264 cli being unable to use a shared library built by ICL however.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=35cf912671fddcb3e701bf667a75f77dd8b28264
---

 configure |    5 ++++-
 x264.h    |   19 +++++++++++++++----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/configure b/configure
index 16970b8..d527e8f 100755
--- a/configure
+++ b/configure
@@ -1091,7 +1091,10 @@ if [ "$shared" = "yes" ]; then
             # MSVC link does not act similarly, so it is required to make an export definition out of x264.h and use it at link time
             echo "SOFLAGS=-dll -def:x264.def -implib:\$(IMPLIBNAME) $SOFLAGS" >> config.mak
             echo "EXPORTS" > x264.def
-            grep "^\(int\|void\|x264_t\|extern\).*x264.*[\[(;]" ${SRCPATH}/x264.h | sed -e "s/.*\(x264.*\)[\[(].*/\1/;s/.*\(x264.*\);/\1/;s/open/open_$API/g" >> x264.def
+            # export API functions
+            grep "^\(int\|void\|x264_t\).*x264" ${SRCPATH}/x264.h | sed -e "s/.*\(x264.*\)(.*/\1/;s/open/open_$API/g" >> x264.def
+            # export API variables/data. must be flagged with the DATA keyword
+            grep "extern.*x264" ${SRCPATH}/x264.h | sed -e "s/.*\(x264\w*\)\W.*/\1 DATA/;" >> x264.def
         else
             echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
             echo "SOFLAGS=-shared -Wl,--out-implib,\$(IMPLIBNAME) -Wl,--enable-auto-image-base $SOFLAGS" >> config.mak
diff --git a/x264.h b/x264.h
index efc61bc..9219114 100644
--- a/x264.h
+++ b/x264.h
@@ -41,7 +41,18 @@
 
 #include "x264_config.h"
 
-#define X264_BUILD 122
+#define X264_BUILD 123
+
+/* Application developers planning to link against a shared library version of
+ * libx264 from a Microsoft Visual Studio or similar development environment
+ * will need to define X264_API_IMPORTS before including this header.
+ * This clause does not apply to MinGW, similar development environments, or non
+ * Windows platforms. */
+#ifdef X264_API_IMPORTS
+#define X264_API __declspec(dllimport)
+#else
+#define X264_API
+#endif
 
 /* x264_t:
  *      opaque handler for encoder */
@@ -516,7 +527,7 @@ typedef struct
 } x264_level_t;
 
 /* all of the levels defined in the standard, terminated by .level_idc=0 */
-extern const x264_level_t x264_levels[];
+X264_API extern const x264_level_t x264_levels[];
 
 /****************************************************************************
  * Basic parameter handling functions
@@ -613,14 +624,14 @@ int     x264_param_apply_profile( x264_param_t *, const char *profile );
  *      (16-x264_bit_depth) bits to be zero.
  *      Note: The flag X264_CSP_HIGH_DEPTH must be used to specify the
  *      colorspace depth as well. */
-extern const int x264_bit_depth;
+X264_API extern const int x264_bit_depth;
 
 /* x264_chroma_format:
  *      Specifies the chroma formats that x264 supports encoding. When this
  *      value is non-zero, then it represents a X264_CSP_* that is the only
  *      chroma format that x264 supports encoding. If the value is 0 then
  *      there are no restrictions. */
-extern const int x264_chroma_format;
+X264_API extern const int x264_chroma_format;
 
 enum pic_struct_e
 {



More information about the x264-devel mailing list