pinterf / TIVTC

TIVTC and TDeint
57 stars 9 forks source link

Compilation errors #44

Closed flossy83 closed 8 months ago

flossy83 commented 8 months ago

I'm trying to make a small tweak/fix to TDecimate's hybrid=3 mode (details here) and have managed to set up the whole MSys2/Mingw64 environment just now for the first time.

The first of the two build commands seems ok:

# cmake .. -G "MinGW Makefiles" -DENABLE_INTEL_SIMD:bool=on
-- The CXX compiler identification is GNU 12.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detected target processor as: AMD64
../common/TCommonASM.cpp;../common/TCommonASM.h;../common/fixedfonts.cpp;../common/fixedfonts.h;../common/info.cpp;../common/info.h;../common/internal.cpp;../common/internal.h;../include/avisynth.h;../include/avs/alignment.h;../include/avs/capi.h;../include/avs/config.h;../include/avs/cpuid.h;../include/avs/filesystem.h;../include/avs/minmax.h;../include/avs/posix.h;../include/avs/types.h;../include/avs/win.h;Cache.cpp;Cache.h;Cycle.cpp;Cycle.h;FieldDiff.cpp;FieldDiff.h;Font.h;FrameDiff.cpp;FrameDiff.h;IsCombedTIVTC.cpp;MergeHints.cpp;MergeHints.h;PlanarFrame.cpp;PlanarFrame.h;PluginInit.cpp;RequestLinear.cpp;RequestLinear.h;TDecimate.cpp;TDecimate.h;TDecimateASM.cpp;TDecimateASM.h;TDecimateBlur.cpp;TDecimateMode2.cpp;TDecimateMode7.cpp;TDecimateOut.cpp;TFM.cpp;TFM.h;TFMASM.cpp;TFMD2V.cpp;TFMPP.cpp;TFMPP.h;TFMPlanar.cpp;TFMYUY2.cpp;TFMasm.h;calcCRC.cpp;calcCRC.h;profUtil.cpp;profUtil.h;resource.h
../common/TCommonASM.cpp;../common/TCommonASM.h;../common/fixedfonts.cpp;../common/fixedfonts.h;../common/info.cpp;../common/info.h;../common/internal.cpp;../common/internal.h;../include/avisynth.h;../include/avs/alignment.h;../include/avs/capi.h;../include/avs/config.h;../include/avs/cpuid.h;../include/avs/filesystem.h;../include/avs/minmax.h;../include/avs/posix.h;../include/avs/types.h;../include/avs/win.h;TDBuf.cpp;TDBuf.h;TDeintASM.cpp;TDeintASM.h;TDeinterlace.cpp;TDeinterlace.h;TDeinterlacePlanar.cpp;TDeinterlaceYUY2.cpp;THelper.cpp;THelper.h;TSwitch.cpp;TSwitch.h;resource.h
-- Configuring done
-- Generating done
-- Build files have been written to: C:/TIVTC-master/src/TIVTC

But the second command fails:

# cmake --build . --config Release
[  2%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/__/common/TCommonASM.cpp.obj
[  5%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/__/common/fixedfonts.cpp.obj
[  7%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/__/common/info.cpp.obj
In file included from C:\TIVTC-master\src\common\info.cpp:27:
C:/TIVTC-master/src/include/avs/win.h:44: warning: "STRICT" redefined
   44 | #define STRICT
      |
In file included from C:/msys64/mingw64/include/windef.h:9,
                 from C:/msys64/mingw64/include/windows.h:69,
                 from C:\TIVTC-master\src\common\internal.h:12,
                 from C:\TIVTC-master\src\common\info.h:30,
                 from C:\TIVTC-master\src\common\info.cpp:23:
C:/msys64/mingw64/include/minwindef.h:11: note: this is the location of the previous definition
   11 | #define STRICT 1
      |
C:\TIVTC-master\src\common\info.h:74:6: error: 'unique_ptr' in namespace 'std' does not name a template type
   74 | std::unique_ptr<BitmapFont> GetBitmapFont(int size, const char* name, bool bold, bool debugSave);
      |      ^~~~~~~~~~
C:\TIVTC-master\src\common\info.h:35:1: note: 'std::unique_ptr' is defined in header '<memory>'; did you forget to '#include <memory>'?
   34 | #include <vector>
  +++ |+#include <memory>
   35 |
C:\TIVTC-master\src\common\info.cpp:46:13: error: 'unique_ptr' in namespace 'std' does not name a template type
   46 | static std::unique_ptr<wchar_t[]> AnsiToWideCharACP(const char* s_ansi)
      |             ^~~~~~~~~~
C:\TIVTC-master\src\common\info.cpp:44:1: note: 'std::unique_ptr' is defined in header '<memory>'; did you forget to '#include <memory>'?
   43 | #include "fixedfonts.h"
  +++ |+#include <memory>
   44 |
C:\TIVTC-master\src\common\info.cpp:55:13: error: 'unique_ptr' in namespace 'std' does not name a template type
   55 | static std::unique_ptr<wchar_t[]> Utf8ToWideChar(const char* s_ansi)
      |             ^~~~~~~~~~
C:\TIVTC-master\src\common\info.cpp:55:8: note: 'std::unique_ptr' is defined in header '<memory>'; did you forget to '#include <memory>'?
   55 | static std::unique_ptr<wchar_t[]> Utf8ToWideChar(const char* s_ansi)
      |        ^~~
C:\TIVTC-master\src\common\info.cpp: In function 'std::wstring charToWstring(const char*, bool)':
C:\TIVTC-master\src\common\info.cpp:110:20: error: 'AnsiToWideCharACP' was not declared in this scope
  110 |     auto wsource = AnsiToWideCharACP(text);
      |                    ^~~~~~~~~~~~~~~~~
C:\TIVTC-master\src\common\info.cpp: At global scope:
C:\TIVTC-master\src\common\info.cpp:906:6: error: 'unique_ptr' in namespace 'std' does not name a template type
  906 | std::unique_ptr<BitmapFont> GetBitmapFont(int size, const char *name, bool bold, bool debugSave) {
      |      ^~~~~~~~~~
C:\TIVTC-master\src\common\info.cpp:906:1: note: 'std::unique_ptr' is defined in header '<memory>'; did you forget to '#include <memory>'?
  906 | std::unique_ptr<BitmapFont> GetBitmapFont(int size, const char *name, bool bold, bool debugSave) {
      | ^~~
C:\TIVTC-master\src\common\info.cpp: In function 'void DrawStringPlanar(VideoInfo&, PVideoFrame&, int, int, const char*)':
C:\TIVTC-master\src\common\info.cpp:1142:8: error: 'unique_ptr' is not a member of 'std'
 1142 |   std::unique_ptr<BitmapFont> current_font = GetBitmapFont(20, "info_h", false, false); // 10x20
      |        ^~~~~~~~~~
C:\TIVTC-master\src\common\info.cpp:1142:8: note: 'std::unique_ptr' is defined in header '<memory>'; did you forget to '#include <memory>'?
C:\TIVTC-master\src\common\info.cpp:1142:29: error: expected primary-expression before '>' token
 1142 |   std::unique_ptr<BitmapFont> current_font = GetBitmapFont(20, "info_h", false, false); // 10x20
      |                             ^
C:\TIVTC-master\src\common\info.cpp:1142:31: error: 'current_font' was not declared in this scope
 1142 |   std::unique_ptr<BitmapFont> current_font = GetBitmapFont(20, "info_h", false, false); // 10x20
      |                               ^~~~~~~~~~~~
C:\TIVTC-master\src\common\info.cpp:1142:46: error: 'GetBitmapFont' was not declared in this scope; did you mean 'BitmapFont'?
 1142 |   std::unique_ptr<BitmapFont> current_font = GetBitmapFont(20, "info_h", false, false); // 10x20
      |                                              ^~~~~~~~~~~~~
      |                                              BitmapFont
mingw32-make[2]: *** [TIVTC\CMakeFiles\TIVTC.dir\build.make:106: TIVTC/CMakeFiles/TIVTC.dir/__/common/info.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:142: TIVTC/CMakeFiles/TIVTC.dir/all] Error 2
mingw32-make: *** [Makefile:135: all] Error 2

The only thing that stands out to me is the last 3 lines "mingw32-make" - shouldn't that be mingw64?

Here are my installed MinGW packages btw:

mingw-w64-ucrt-x86_64-binutils 2.39-2
mingw-w64-ucrt-x86_64-crt-git 10.0.0.r113.g57fd0b77a-1
mingw-w64-ucrt-x86_64-gcc 12.2.0-4
mingw-w64-ucrt-x86_64-gcc-libs 12.2.0-4
mingw-w64-ucrt-x86_64-gcc-objc 12.2.0-4
mingw-w64-ucrt-x86_64-gmp 6.2.1-3
mingw-w64-ucrt-x86_64-headers-git 10.0.0.r113.g57fd0b77a-1
mingw-w64-ucrt-x86_64-isl 0.25-1
mingw-w64-ucrt-x86_64-libgccjit 12.2.0-4
mingw-w64-ucrt-x86_64-libiconv 1.17-1
mingw-w64-ucrt-x86_64-libwinpthread-git 10.0.0.r113.g57fd0b77a-1
mingw-w64-ucrt-x86_64-mpc 1.2.1-1
mingw-w64-ucrt-x86_64-mpfr 4.1.0.p13-1
mingw-w64-ucrt-x86_64-windows-default-manifest 6.4-4
mingw-w64-ucrt-x86_64-winpthreads-git 10.0.0.r113.g57fd0b77a-1
mingw-w64-ucrt-x86_64-zlib 1.2.13-1
mingw-w64-ucrt-x86_64-zstd 1.5.2-2
mingw-w64-x86_64-binutils 2.39-2
mingw-w64-x86_64-brotli 1.0.9-5
mingw-w64-x86_64-bzip2 1.0.8-2
mingw-w64-x86_64-c-ares 1.18.1-1
mingw-w64-x86_64-ca-certificates 20211016-3
mingw-w64-x86_64-cmake 3.24.2-4
mingw-w64-x86_64-crt-git 10.0.0.r113.g57fd0b77a-1
mingw-w64-x86_64-curl 7.86.0-2
mingw-w64-x86_64-expat 2.4.9-1
mingw-w64-x86_64-gcc 12.2.0-4
mingw-w64-x86_64-gcc-libs 12.2.0-4
mingw-w64-x86_64-gcc-objc 12.2.0-4
mingw-w64-x86_64-gettext 0.21-3
mingw-w64-x86_64-gmp 6.2.1-3
mingw-w64-x86_64-headers-git 10.0.0.r113.g57fd0b77a-1
mingw-w64-x86_64-isl 0.25-1
mingw-w64-x86_64-jansson 2.14-2
mingw-w64-x86_64-jemalloc 5.3.0-1
mingw-w64-x86_64-jsoncpp 1.9.5-1
mingw-w64-x86_64-libarchive 3.6.1-2
mingw-w64-x86_64-libb2 0.98.1-2
mingw-w64-x86_64-libffi 3.4.3-1
mingw-w64-x86_64-libgccjit 12.2.0-4
mingw-w64-x86_64-libiconv 1.17-1
mingw-w64-x86_64-libidn2 2.3.3-1
mingw-w64-x86_64-libpsl 0.21.1-4
mingw-w64-x86_64-libssh2 1.10.0-1
mingw-w64-x86_64-libsystre 1.0.1-4
mingw-w64-x86_64-libtasn1 4.19.0-1
mingw-w64-x86_64-libtre-git r128.6fb7206-2
mingw-w64-x86_64-libunistring 1.0-1
mingw-w64-x86_64-libuv 1.44.2-1
mingw-w64-x86_64-libwinpthread-git 10.0.0.r113.g57fd0b77a-1
mingw-w64-x86_64-libxml2 2.10.3-1
mingw-w64-x86_64-lz4 1.9.4-1
mingw-w64-x86_64-make 4.3-1
mingw-w64-x86_64-mpc 1.2.1-1
mingw-w64-x86_64-mpfr 4.1.0.p13-1
mingw-w64-x86_64-nghttp2 1.50.0-1
mingw-w64-x86_64-ninja 1.11.1-2
mingw-w64-x86_64-openssl 1.1.1.q-1
mingw-w64-x86_64-p11-kit 0.24.1-3
mingw-w64-x86_64-pkgconf 1~1.8.0-2
mingw-w64-x86_64-rhash 1.4.3-1
mingw-w64-x86_64-windows-default-manifest 6.4-4
mingw-w64-x86_64-winpthreads-git 10.0.0.r113.g57fd0b77a-1
mingw-w64-x86_64-xz 5.2.7-1
mingw-w64-x86_64-zlib 1.2.13-1
mingw-w64-x86_64-zstd 1.5.2-2

Any help appreciated

flossy83 commented 8 months ago

Oh I tried putting #include <memory> in info.h and info.cpp like the compiler error suggested and it works now, I get a TIVTC.dll file.

But, Avisynth doesn't see it:

Untitled-1

edit: I tried LoadPlugin() and LoadCPlugin(), no effect.

I guess it must have built wrongly - here is the built file.

It looks like the first make command autodetected my CPU as AMD - "-- Detected target processor as: AMD64". Is that correct? My CPU is Intel i5-4570. Are there some makefile switches I can set to tell it to try building a different version?

Here is the successful second build output:

# cmake --build . --config Release
[  2%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/__/common/TCommonASM.cpp.obj
[  5%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/__/common/fixedfonts.cpp.obj
[  7%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/__/common/info.cpp.obj
In file included from C:\TIVTC-master\src\common\info.cpp:27:
C:/TIVTC-master/src/include/avs/win.h:44: warning: "STRICT" redefined
   44 | #define STRICT
      |
In file included from C:/msys64/mingw64/include/windef.h:9,
                 from C:/msys64/mingw64/include/windows.h:69,
                 from C:\TIVTC-master\src\common\internal.h:12,
                 from C:\TIVTC-master\src\common\info.h:30,
                 from C:\TIVTC-master\src\common\info.cpp:23:
C:/msys64/mingw64/include/minwindef.h:11: note: this is the location of the previous definition
   11 | #define STRICT 1
      |
[ 10%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/__/common/internal.cpp.obj
[ 12%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/Cache.cpp.obj
[ 15%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/Cycle.cpp.obj
[ 17%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/FieldDiff.cpp.obj
[ 20%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/FrameDiff.cpp.obj
[ 22%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/IsCombedTIVTC.cpp.obj
[ 25%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/MergeHints.cpp.obj
[ 27%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/PlanarFrame.cpp.obj
[ 30%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/PluginInit.cpp.obj
[ 32%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/RequestLinear.cpp.obj
[ 35%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/TDecimate.cpp.obj
[ 37%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/TDecimateASM.cpp.obj
[ 40%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/TDecimateBlur.cpp.obj
[ 42%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/TDecimateMode2.cpp.obj
[ 45%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/TDecimateMode7.cpp.obj
[ 47%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/TDecimateOut.cpp.obj
[ 50%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/TFM.cpp.obj
[ 52%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/TFMASM.cpp.obj
[ 55%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/TFMD2V.cpp.obj
[ 57%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/TFMPP.cpp.obj
[ 60%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/TFMPlanar.cpp.obj
[ 62%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/TFMYUY2.cpp.obj
[ 65%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/calcCRC.cpp.obj
[ 67%] Building CXX object TIVTC/CMakeFiles/TIVTC.dir/profUtil.cpp.obj
[ 70%] Linking CXX shared library TIVTC.dll
[ 70%] Built target TIVTC
[ 72%] Building CXX object TDeint/CMakeFiles/TDeint.dir/__/common/TCommonASM.cpp.obj
[ 75%] Building CXX object TDeint/CMakeFiles/TDeint.dir/__/common/fixedfonts.cpp.obj
[ 77%] Building CXX object TDeint/CMakeFiles/TDeint.dir/__/common/info.cpp.obj
In file included from C:\TIVTC-master\src\common\info.cpp:27:
C:/TIVTC-master/src/include/avs/win.h:44: warning: "STRICT" redefined
   44 | #define STRICT
      |
In file included from C:/msys64/mingw64/include/windef.h:9,
                 from C:/msys64/mingw64/include/windows.h:69,
                 from C:\TIVTC-master\src\common\internal.h:12,
                 from C:\TIVTC-master\src\common\info.h:30,
                 from C:\TIVTC-master\src\common\info.cpp:23:
C:/msys64/mingw64/include/minwindef.h:11: note: this is the location of the previous definition
   11 | #define STRICT 1
      |
[ 80%] Building CXX object TDeint/CMakeFiles/TDeint.dir/__/common/internal.cpp.obj
[ 82%] Building CXX object TDeint/CMakeFiles/TDeint.dir/TDBuf.cpp.obj
[ 85%] Building CXX object TDeint/CMakeFiles/TDeint.dir/TDeintASM.cpp.obj
[ 87%] Building CXX object TDeint/CMakeFiles/TDeint.dir/TDeinterlace.cpp.obj
[ 90%] Building CXX object TDeint/CMakeFiles/TDeint.dir/TDeinterlacePlanar.cpp.obj
[ 92%] Building CXX object TDeint/CMakeFiles/TDeint.dir/TDeinterlaceYUY2.cpp.obj
[ 95%] Building CXX object TDeint/CMakeFiles/TDeint.dir/THelper.cpp.obj
[ 97%] Building CXX object TDeint/CMakeFiles/TDeint.dir/TSwitch.cpp.obj
[100%] Linking CXX shared library TDeint.dll
[100%] Built target TDeint
flossy83 commented 8 months ago

If I move the TIVTC.dll to another location, eg. C:\ and do a LoadPlugin("C:\TIVTC.dll") then I get a meaningful error message code 126:

debug avs_snapshot_00 01 356

I don't know why it shows it as forward slash, it's definitely a backslash in my script

flossy83 commented 8 months ago

Seems to be missing some libgcc dependencies...

Untitled-1 copy

flossy83 commented 8 months ago

I think I need to tell GCC to include those dependencies in the compilation, but I don't know how

flossy83 commented 8 months ago

According to a StackOverflow post I need to compile with flags: -static-libstdc++ -static-libgcc

But I'm not sure how to do that -- do I need to modify the makefiles?

flossy83 commented 8 months ago

Tried putting set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") inside all CMakeLists.txt files to no effect

pinterf commented 8 months ago

Are you using mingw built Avisynth+? Mingw and Windows-style DLLs are not ABI compatible. Plugin using C interface has no problems, but they are very rare. The real expert of MSys2/Mingw64 is @qyot27, I'd ask him.

flossy83 commented 8 months ago

Are you using mingw built Avisynth+?

I'm using the current latest public release from the GitHub repository, so I guess that means no.

I managed to include all those GCC dependencies in TIVTC.dll by putting set(CMAKE_CXX_FLAGS "-static") inside all CMakeLists.txt files - in this case Avisynth Info Tool reports no problems with the .dll but I still get the "no function named TDecimate" when trying to call TDecimate().

But LoadPlugin("C:\TIVTC.dll") doesn't throw an error anymore, and the TIVTC.dll is bigger so I know it included those GCC dependencies.

So I guess the GCC builds just aren't compatible with the public release build of Avisynth, so I probably have to use Visual Studio to compile it instead, have I got that right? How are you compiling it?

pinterf commented 8 months ago

Yes, mingw built C++ plugins are compatible only with mingw build Avisynth+. (following the README.md build instructions I've encountered the missing header, so I fixed it). As for Visual Studio: open the solution file (.sln) in the IDE and build the project. I usually do this.

pinterf commented 8 months ago

(As for mingw built DLL / Load error 126: The missing DLLs (standard c++ library, posix threads, library (but I don't think TIVTC is using that) are somewhere in your gcc directory. The command ldd <your_dll_name> can list the dependencies if they are not statically linked (as you finally did).

qyot27 commented 8 months ago

It looks like the first make command autodetected my CPU as AMD - "-- Detected target processor as: AMD64". Is that correct? My CPU is Intel i5-4570. Are there some makefile switches I can set to tell it to try building a different version?

amd64 is just the architecture name used by some distros and projects, because AMD was the one that actually extended x86 into x86_64.

Using VS through the command-line CMake interface can be done by first launching the Visual Studio Command Prompt and specifying "Visual Studio XX 20YY" as the generator, where the XX and YY refer to whatever version of VS is being used (16 2019, for example).

Overriding/appending CMAKE_CXX_FLAGS or CMAKE_SHARED_LINKER_FLAGS doesn't usually involve needing to edit CMakeLists.txt, as virtually every sort of thing you can set() inside of them can also be passed to the CLI at configure time, e.g. -DCMAKE_CXX_FLAGS="-static" or -DCMAKE_SHARED_LINKER_FLAGS="-static-libgcc".

But yes, as stated, GCC and MSVC use incompatible C++ ABIs and you can't mix and match host and plugins across compilers. And by default, GCC-built AviSynth+ actually looks in a completely different set of directories for plugins (plugins_gcc and plugins64_gcc), so as not to cause load errors.

flossy83 commented 8 months ago

Thanks, a bit disappointing as I was trying to avoid using the Visual Studio GUI . I tried the 2019 Community version and it's ok but it only lets me compile the CLang version due to missing compilation tools. Guess I need the 2022 version?

pinterf commented 8 months ago

The solution and project files are set to v143 platform toolset, this is what vs2022 uses. For vs2019 go into config and change that to v142 toolset, that must be fine.