]> git.videolan.org Git - x264.git/commitdiff
ICL/MSVS: Fix shared library generation and usage
authorSteven Walters <kemuri9@gmail.com>
Thu, 29 Mar 2012 01:15:04 +0000 (21:15 -0400)
committerJason Garrett-Glaser <jason@x264.com>
Mon, 23 Apr 2012 20:28:34 +0000 (13:28 -0700)
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.

configure
x264.h

index 16970b830a3255121a700f5a0cc3cd18e77cae77..d527e8ff6cbc8db52b9b62373b5557f17aa736b9 100755 (executable)
--- 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 efc61bc085a902ffff42ab3ffdbb1b6f1aec13b9..92191147cbbfb0284383c4bbdcd6d6abb7c36aa2 100644 (file)
--- a/x264.h
+++ b/x264.h
 
 #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
 {