MinGW build static library doesn't work

Issue #439 new
Former user created an issue

Hello everyone.

I've tried to build ffmpeg with --enable-libx265 and it complained that could not found x265.

The configure.log explains, that indeed it couldn't compile the following sample

#include <x265.h> #include <stdint.h>

long check_x265_api_get(void) { return (long) x265_api_get; }

int main(void) { int ret = 0; ret |= ((intptr_t)check_x265_api_get) & 0xFFFF; return ret; }

I've tried to compile the same sample and have got the following issue:

grin@DESKTOP-REF529A /c/workspace/tmp $ gcc pkg-config --cflags x265 pkg-config --libs x265 --static test.c C:\Users\grin\AppData\Local\Temp\cc2ilb2S.o:test.c:(.text+0x4): undefined reference to `x265_api_get_165' collect2.exe: error: ld returned 1 exit status

Library libx265.a was successfully found through pkg-config. And nm.exe says, that it contains appropriate function.

grin@DESKTOP-REF529A /c/workspace/tmp $ pkg-config --libs x265 -Lc:/Qt/Tools/mingw530_32/lib -lx265

grin@DESKTOP-REF529A /c/workspace/tmp $ nm c:/Qt/Tools/mingw530_32/lib/libx265.a | grep x265_api_get 00003d20 T _x265_api_get_165

Where am I wrong and what shall I change for correct compiling the example?

I hope for your help. Thank you.

Comments (12)

  1. M CHEN

    The symbol is x265_api_get_165 vs _x265_api_get_165.

    It looks ABI conflict, it means the lib and application compile with different compiler, we can simple change symbol table, but I worried there have some potential compatibility issues.

  2. Rinat Gadelshin

    Thank you for your fast reply =)

    I've made x265 from the msys my the mingw530_32 toolchain. Then (from the same unclosed terminal), I've tried to build the ffmpeg. And after the error I've tried to build the test.c from the same terminal. I can't figure out how can it be different compilers (for x265 and the test.c) in this case. Can you detect compiler for the _x265_api_get_165 (which was discovered by nm.exe)?

  3. Rinat Gadelshin

    Can it be msvc? I have installed VS2015. But cmake log (stdout) of building x265 said, that the GNU C (mingw's gcc) was detected.

  4. M CHEN
    I have been double checked, I keep my mind, it looks your compiler issues.
    
    My environment:
    
    gcc version 7.3.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project)
    
    build/msys
    ./make-Makefiles.sh
    gcc -o test test.c -lx265 -lstdc++
    
    nm libx265.a | grep -a x265_api_get
    0000000000003830 T x265_api_get_165
    
    The symbol have not prefix '_', it is GCC specification.
    Could you please check really compiler called in your environment?
    
  5. Rinat Gadelshin

    I've rebuild libx265.a (static) by mingw 7.3.0. The '_' has gone, but undefined reference has stayed

    grin@DESKTOP-REF529A /c/workspace/tmp
    $ nm /c/Qt/Tools/mingw730_64/lib/libx265.a | grep x265_api_get
    0000000000003830 T x265_api_get_165
    
    grin@DESKTOP-REF529A /c/workspace/tmp
    $ gcc `pkg-config --cflags x265` `pkg-config --libs x265 --static` test.c
    test.c: In function 'check_x265_api_get':
    test.c:5:9: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
      return (long) x265_api_get;
             ^
    C:\Users\grin\AppData\Local\Temp\cc2U1mJl.o:test.c:(.rdata$.refptr.x265_api_get_165[.refptr.x265_api_get_165]+0x0): undefined reference to `x265_api_get_165'
    collect2.exe: error: ld returned 1 exit status
    
  6. Rinat Gadelshin

    My env output (from msys):

    grin@DESKTOP-REF529A /c/workspace/tmp
    $ env
    USERDOMAIN_ROAMINGPROFILE=DESKTOP-REF529A
    HOMEPATH=\
    APPDATA=C:\Users\grin\AppData\Roaming
    QUAZIP_HOME=c:\workspace\RR-deps\QuaZip
    PROGRAMW6432=C:\Program Files
    ONEDRIVE=C:\Users\grin\OneDrive
    TERM=cygwin
    ZLIB_HEADERS_PATH=c:\workspace\3rdparty\zlib-1.2.3
    PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
    WINDIR=C:\Windows
    COMMONPROGRAMW6432=C:\Program Files\Common Files
    PUBLIC=C:\Users\Public
    OLDPWD=/c/workspace/3rdparty/x265/build/msys
    PROGRAMDATA=C:\ProgramData
    USERDOMAIN=DESKTOP-REF529A
    COMMONPROGRAMFILES(X86)=C:\Program Files (x86)\Common Files
    OS=Windows_NT
    ALLUSERSPROFILE=C:\ProgramData
    !::=::\
    TEMP=/tmp
    COMMONPROGRAMFILES=C:\Program Files (x86)\Common Files
    USERNAME=grin
    PROCESSOR_LEVEL=6
    PATH=/c/Qt/Tools/mingw730_64/bin:/c/Program Files (x86)/NASM/:.:/usr/local/bin:/mingw/bin:/bin:/c/Program Files (x86)/IntelSWTools/Intel(R) Media SDK 2018 R2/Software Development Kit/bin/x64:/c/Program Files (x86)/IntelSWTools/Intel(R) Media SDK 2018 R2/Software Development Kit/bin/win32:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/c/Windows/System32/OpenSSH/:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c/Program Files/CMake/bin:/c/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit/:/c/Users/grin/.dnx/bin:/c/Program Files/Microsoft DNX/Dnvm/:/c/Program Files/Microsoft SQL Server/130/Tools/Binn/:/c/Program Files/TortoiseHg/:/c/Users/grin/AppData/Local/Programs/Python/Python37-32/Scripts/:/c/Users/grin/AppData/Local/Programs/Python/Python37-32/:/c/Users/grin/AppData/Local/Microsoft/WindowsApps:/c/Users/grin/bin:/c/Program Files (x86)/NSIS:/c/Program Files (x86)/NSIS/bin:.}
    PSMODULEPATH=C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
    MSYSCON=sh.exe
    INTELMEDIASDKROOT=C:\Program Files (x86)\IntelSWTools\Intel(R) Media SDK 2018 R2\Software Development Kit\
    PWD=/c/workspace/tmp
    SYSTEMDRIVE=C:
    PROCESSOR_ARCHITEW6432=AMD64
    USERPROFILE=C:\Users\grin
    PS1=\[\033]0;$MSYSTEM:\w\007
    \033[32m\]\u@\h \[\033[33m\w\033[0m\]
    $
    LOGONSERVER=\\DESKTOP-REF529A
    PROCESSOR_ARCHITECTURE=x86
    LOCALAPPDATA=C:\Users\grin\AppData\Local
    DRIVERDATA=C:\Windows\System32\Drivers\DriverData
    !C:=C:\MinGW\msys\1.0
    HOME=/home/grin
    SHLVL=1
    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
    HOMEDRIVE=C:
    WD=C:\MinGW\msys\1.0\\bin\
    PROMPT=$P$G
    MSYSTEM=MINGW32
    COMSPEC=C:\Windows\SysWOW64\cmd.exe
    LOGNAME=grin
    TMP=/tmp
    SYSTEMROOT=C:\Windows
    PROCESSOR_REVISION=3a09
    MAKE_MODE=unix
    PROGRAMFILES=C:\Program Files (x86)
    VS140COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\
    NUMBER_OF_PROCESSORS=4
    PROGRAMFILES(X86)=C:\Program Files (x86)
    SESSIONNAME=Console
    HISTFILE=/home/grin/.bash_history
    COMPUTERNAME=DESKTOP-REF529A
    _=/bin/env
    
  7. M CHEN

    Your build directory is /c/workspace/3rdparty/x265/build/msys, but pkg-config output anther directory. Could you try my command line on above directory?

    gcc -o test test.c -lx265 -lstdc++
    

    It may help confirm the lib was build correct.

  8. Rinat Gadelshin
    grin@DESKTOP-REF529A /c/workspace/tmp
    $ gcc -o test test.c -lx265 -lstdc++
    test.c:1:10: fatal error: x265.h: No such file or directory
     #include <x265.h>
              ^~~~~~~~
    compilation terminated.
    
    grin@DESKTOP-REF529A /c/workspace/tmp
    $ gcc -o test test.c -lx265 -lstdc++ -I/c/Qt/Tools/mingw730_64/include
    test.c: In function 'check_x265_api_get':
    test.c:5:9: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
      return (long) x265_api_get;
             ^
    
    grin@DESKTOP-REF529A /c/workspace/tmp
    $ echo $?
    0
    
  9. Rinat Gadelshin

    but ld says error:

    grin@DESKTOP-REF529A /c/workspace/tmp
    $ ld -L/c/Qt/Tools/mingw730_64/lib -lx265 test.o
    Warning: corrupt .drectve at end of def file
    c:\Qt\Tools\mingw730_64\bin\ld.exe: i386 architecture of input file `test.o' is incompatible with i386:x86-64 output
    test.o:(.text$mn+0x4): undefined reference to `_x265_api_get_165'
    
  10. M CHEN

    This is I worried in before, your compiler and lib may be mismatch, so it report as i386 architecture.

    btw: go to bed, I will reply future message in tomorrow.

  11. Rinat Gadelshin

    Ok. You are quite right. The night has gone. Thank you very much. It's become more clear (not completely, but much more). =)

  12. Log in to comment