ddiakopoulos / libnyquist

:microphone: Cross platform C++11 library for decoding audio (mp3, wav, ogg, opus, flac, etc)
BSD 2-Clause "Simplified" License
540 stars 66 forks source link

mingw: unrecognized options and linking error #50

Closed 4321ba closed 3 years ago

4321ba commented 3 years ago

Hi! I'm trying to cross-compile my project, including this library from ubuntu 20.04 to windows with mingw-w64 7.0.0-2, with this toolchain cmake file and I get this error:

x86_64-w64-mingw32-gcc: error: /arch:AVX: No such file or directory
x86_64-w64-mingw32-gcc: error: /Zi: No such file or directory

which I found in cmake/CXXhelpers.cmake so my guess is that mingw doesn't know these options (and it expects dashes instead of slashes anyway) commenting out line 18 seemed to work

however now I'm getting linking errors:

/usr/bin/x86_64-w64-mingw32-ld: bin/liblibnyquist.a(FlacDependencies.c.obj):FlacDependencies.c:(.text+0x1a6d2): undefined reference to `fopen_utf8'
/usr/bin/x86_64-w64-mingw32-ld: bin/liblibnyquist.a(FlacDependencies.c.obj):FlacDependencies.c:(.text+0x1a7b2): undefined reference to `fopen_utf8'

I actually don't need flac, nor libnyquist to manage fileio, so I just tried commenting out stuff so that it at least compiles but I just generated more errors instead. (Should I use a different library if I don't need half the stuff?) Can someone push me in the right direction?

4321ba commented 3 years ago

I found the problem for the linking error: in src/FlacDependencies.c at line 82-84:

#if defined(_MSC_VER)
#include "FLAC/src/win_utf8_io.c"
#endif

the include is needed, but probably _MSC_VER is not defined when using MinGW commenting out the if and endif worked again and now it runs yay!! it would be cool if these would be fixed (so I could use it in a git submodule cleanly :D)

I'd love to create a pull request to fix these 2, but I don't want to break every other platform. I'll try my best at least:

for the 2nd one I found this: if defined(_WIN32) || defined(_WIN64) which could replace _MSC_VER and possibly work

for the 1st one:

    if (WIN32)
        target_compile_options(${proj} PRIVATE /arch:AVX /Zi )
    endif()

I found that instead of if (WIN32) maybe if (MSVC) would work based on this

I'll create a PR soon