Opened 7 years ago

Closed 6 years ago

#7229 closed defect (invalid)

Compilation error with --enable-libfreetype

Reported by: CoRoNe Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords: libfreetype
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

I'm cross-compiling on Windows (using Cygwin, MinGW and GCC). I've compiled and installed Freetype 2.9.1, but when I then compile a shared ffmpeg build (fe84f70 in this case) I'm suddenly getting the following error:

LD      libavfilter/avfilter-7.dll
/cygdrive/[...]/i686-w64-mingw32/lib/libfreetype.a(ftbase.o):ftbase.c:(.text+0x22a0): multiple definition of `FT_Done_Face'
libavformat/libavformat.dll.a(d000017.o):(.text+0x0): first defined here
/cygdrive/[...]/i686-w64-mingw32/lib/libfreetype.a(ftbase.o):ftbase.c:(.text+0x2ab0): multiple definition of `FT_Set_Char_Size'
libavformat/libavformat.dll.a(d000104.o):(.text+0x0): first defined here
/cygdrive/[...]/i686-w64-mingw32/lib/libfreetype.a(ftbase.o):ftbase.c:(.text+0x2b50): multiple definition of `FT_Set_Pixel_Sizes'
libavformat/libavformat.dll.a(d000108.o):(.text+0x0): first defined here
/cygdrive/[...]/i686-w64-mingw32/lib/libfreetype.a(ftbase.o):ftbase.c:(.text+0x2bd0): multiple definition of `FT_Get_Kerning'
libavformat/libavformat.dll.a(d000037.o):(.text+0x0): first defined here
/cygdrive/[...]/i686-w64-mingw32/lib/libfreetype.a(ftbase.o):ftbase.c:(.text+0x5570): multiple definition of `FT_Load_Char'
libavformat/libavformat.dll.a(d000066.o):(.text+0x0): first defined here
/cygdrive/[...]/i686-w64-mingw32/lib/libfreetype.a(ftbase.o):ftbase.c:(.text+0xac20): multiple definition of `FT_New_Face'
libavformat/libavformat.dll.a(d000073.o):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [ffbuild/library.mak:103: libavfilter/avfilter-7.dll] Error 1

Is this a regression in FFmpeg?

Change History (10)

comment:1 by CoRoNe, 7 years ago

Linking against Freetype 2.9 works just fine:

LD      libavfilter/avfilter-7.dll
/cygdrive/[...]/i686-w64-mingw32-dlltool -m i386 -d libavfilter/avfilter-7.def -l libavfilter/avfilter.lib -D avfilter-7.dll

To be clear, I've also reported this to the developers of Freetype, but they suggest I come here first.

comment:2 by CoRoNe, 6 years ago

Does anyone have any idea?

comment:3 by James, 6 years ago

Can you provide more details? What's the configure line you used? And are you sure your environment is sane? I can't seem to reproduce this using MinGW on an msys2 environment.

comment:4 by Carl Eugen Hoyos, 6 years ago

Keywords: multiple definition of freetype removed

comment:5 by CoRoNe, 6 years ago

As I wasn't sure my environment was sane anymore, I nuked my sandbox and started over fresh. I've updated MinGW-w64 to v5.0.4 and GCC v8.1.0, but in the end it didn't matter one bit, because with the following configure line I got the same error as in my first post:

./configure --arch=x86 --target-os=mingw32 --cross-prefix=/cygdrive/m/ffmpeg-wind
ows-build-helpers-master/ffmpeg_local_builds/sandbox/cross_compilers/mingw-w64-i6
86/bin/i686-w64-mingw32- --pkg-config=pkg-config --pkg-config-flags=--static --ex
tra-version=Reino --enable-gray --enable-version3 --disable-debug --disable-doc -
-disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --dis
able-w32threads --enable-avisynth --enable-frei0r --enable-filter=frei0r --enable
-gmp --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-lib
bs2b --enable-libcaca --extra-cflags=-DCACA_STATIC --enable-libfdk-aac --enable-l
ibflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-
libgme --enable-libgsm --enable-libilbc --enable-libmp3lame --enable-libmysofa --
enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable
-libopenmpt --enable-libopus --enable-librubberband --enable-libsnappy --enable-l
ibsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --extra-cflags=-D
LIBTWOLAME_STATIC --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis 
--enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxa
vs --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzvbi --enable-m
bedtls --extra-cflags='-march=pentium3' --extra-cflags='-mtune=athlon-xp' --extra
-cflags=-O2 --extra-cflags='-mfpmath=sse' --extra-cflags=-msse --enable-shared --
disable-static --prefix=/cygdrive/m/ffmpeg-windows-build-helpers-master/ffmpeg_lo
cal_builds/sandbox/win32/ffmpeg_git_shared

comment:6 by James, 6 years ago

Reproduced by developer: set
Status: newopen

Confirmed with "./configure --enable-libfreetype --enable-libbluray --pkg-config-flags=--static --enable-shared --disable-static && make libavfilter/avfilter-7.dll" only when using static libraries from both libbluray and libfreetype (.a and not .dll.a).
Using shared libfreetype 2.9.1 links fine.

This is unlikely to be an ffmpeg issue. Sounds more like either libfreetype of the binutils' linker at fault.

comment:7 by CoRoNe, 6 years ago

I've solved the issue.
While browsing Freetype's commits I came across d2d1750. I've had compilation failures with "declspec" before.

diff -ur builds/unix/ftconfig.in.bak builds/unix/ftconfig.in
--- builds/unix/ftconfig.in.bak	2018-04-22 11:41:36.000000000 +0200
+++ builds/unix/ftconfig.in	2018-06-13 21:58:02.093750000 +0200
@@ -490,7 +490,7 @@
 #ifdef FT2_BUILD_LIBRARY
 
 #if defined( _WIN32 ) && ( defined( _DLL ) || defined( DLL_EXPORT ) )
-#define FT_EXPORT( x )  __declspec( dllexport )  x
+#define FT_EXPORT( x )  x
 #elif defined( __GNUC__ ) && __GNUC__ >= 4
 #define FT_EXPORT( x )  __attribute__(( visibility( "default" ) ))  x
 #elif defined( __cplusplus )
@@ -502,7 +502,7 @@
 #else
 
 #if defined( FT2_DLLIMPORT )
-#define FT_EXPORT( x )  __declspec( dllimport )  x
+#define FT_EXPORT( x )  x
 #elif defined( __cplusplus )
 #define FT_EXPORT( x )  extern "C"  x
 #else
diff -ur include/freetype/config/ftconfig.h.bak include/freetype/config/ftconfig.h
--- include/freetype/config/ftconfig.h.bak	2018-04-22 11:41:36.000000000 +0200
+++ include/freetype/config/ftconfig.h	2018-06-13 21:58:46.234375000 +0200
@@ -458,7 +458,7 @@
 #ifdef FT2_BUILD_LIBRARY
 
 #if defined( _WIN32 ) && ( defined( _DLL ) || defined( DLL_EXPORT ) )
-#define FT_EXPORT( x )  __declspec( dllexport )  x
+#define FT_EXPORT( x )  x
 #elif defined( __GNUC__ ) && __GNUC__ >= 4
 #define FT_EXPORT( x )  __attribute__(( visibility( "default" ) ))  x
 #elif defined( __cplusplus )
@@ -470,7 +470,7 @@
 #else
 
 #if defined( FT2_DLLIMPORT )
-#define FT_EXPORT( x )  __declspec( dllimport )  x
+#define FT_EXPORT( x )  x
 #elif defined( __cplusplus )
 #define FT_EXPORT( x )  extern "C"  x
 #else

I've removed all mentions of __declspec, recompiled freetype, but also those that depend on it (fontconfig, libbluray and libass) and of course ffmpeg in the end. This proved successful and got me a working shared build.

comment:8 by CoRoNe, 6 years ago

The fix I presented above is more of a workaround. According to Alexei Podtelezhnikov (from the Freetype team) DLL_EXPORT and FT2_BUILD_LIBRARY shouldn't be defined if I build a static Freetype library and the 'fix' should therefor not be needed.
He has had a look at my logs and says "The errors suggest that both libfreetype.a and libavformat.dll.a provide FreeType. That would be a problem to link togeher."
You say you reproduced this issue, James. Do you, or anyone else, have any idea what could be the cause and perhaps more important; is this a Freetype or a FFmpeg issue?

comment:9 by CoRoNe, 6 years ago

I guess it was a Freetype issue after all. The "Fortify dllexport/dllimport attributes "-commit fixed it for me. If it does the same for you, James, then you can close this ticket as far as I'm concerned.

comment:10 by Carl Eugen Hoyos, 6 years ago

Resolution: invalid
Status: openclosed

Thank you for testing again!

Note: See TracTickets for help on using tickets.