boletales / sdl2-mixer

Other
1 stars 0 forks source link

Building issue on Windows #1

Open locallycompact opened 6 months ago

locallycompact commented 6 months ago

Can you explain why this flag is needed? I am not a fan of cabal flags as they make CI a nightmare. I would prefer a separate package in the same repo, but why is it causing a problem?

boletales commented 6 months ago

I'm not pretty sure why the problem happens, but when sdl2-mixer is compiled on Windows it fails with error:

[4 of 4] Compiling Paths_sdl2_mixer
Preprocessing executable 'sdl2-mixer-basic-raw' for sdl2-mixer-1.2.0.0..
Building executable 'sdl2-mixer-basic-raw' for sdl2-mixer-1.2.0.0..
Linking .stack-work\dist\0a54338c\build\sdl2-mixer-basic-raw\sdl2-mixer-basic-raw.exe ...
C://Users//myname//AppData//Local//Programs//stack//x86_64-windows//ghc-9.2.4//mingw//bin/ld.exe: C:\Users\myname\AppData\Local\Temp\ghc10740_0\ghc_4.o:ghc_3.c:(.text+0x0): multiple definition of `main'; C://Users//myname//AppData//Local//Programs//stack//x86_64-windows//ghc-9.2.4//mingw//bin/../x86_64-w64-mingw32/lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):D:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:17: first defined here
C://Users//myname//AppData//Local//Programs//stack//x86_64-windows//ghc-9.2.4//mingw//bin/ld.exe: C:\Users\myname\AppData\Local\Programs\stack\x86_64-windows\ghc-9.2.4\lib\x86_64-windows-ghc-9.2.4\rts-1.0.2/libHSrts-1.0.2_thr.a(RtsStartup.thr_o): in function `x86_init_fpu':

C:\GitLabRunner\builds\1\1123228\rts\RtsStartup.c:98:0: error:
     multiple definition of `_fpreset'; C://Users//myname//AppData//Local//Programs//stack//x86_64-windows//ghc-9.2.4//mingw//bin/../x86_64-w64-mingw32/lib/libmingw32.a(lib64_libmingw32_a-CRT_fp10.o):D:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/CRT_fp10.c:19: first defined here
C://Users//myname//AppData//Local//Programs//stack//x86_64-windows//ghc-9.2.4//mingw//bin/ld.exe: C:\Users\myname\AppData\Local\Programs\stack\x86_64-windows\ghc-9.2.4\lib\x86_64-windows-ghc-9.2.4\rts-1.0.2/libHSrts-1.0.2_thr.a(RtsStartup.thr_o): in function `x86_init_fpu':

C:\GitLabRunner\builds\1\1123228\rts\RtsStartup.c:98:0: error:
     multiple definition of `fpreset'; C://Users//myname//AppData//Local//Programs//stack//x86_64-windows//ghc-9.2.4//mingw//bin/../x86_64-w64-mingw32/lib/libmingw32.a(lib64_libmingw32_a-CRT_fp10.o):D:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/CRT_fp10.c:19: first defined here
C://Users//myname//AppData//Local//Programs//stack//x86_64-windows//ghc-9.2.4//mingw//bin/ld.exe: C:\Users\myname\AppData\Local\Programs\stack\x86_64-windows\msys2-20230526\mingw64\lib/libSDL2main.a(SDL_windows_main.c.obj):(.text+0x152): undefined reference to `SDL_main'
collect2.exe: error: ld returned 1 exit status
`gcc.exe' failed in phase `Linker'. (Exit code: 1)

Error: [S-7282]
       Stack failed to execute the build plan.

       While executing the build plan, Stack encountered the error:

       [S-7011]
       While building package sdl2-mixer-1.2.0.0 (scroll up to its section to see the error) using:
       C:\Users\myname\AppData\Roaming\stack\setup-exe-cache\x86_64-windows\Cabal-simple_9p6GVs8J_3.6.3.0_ghc-9.2.4.exe --verbose=1 --builddir=.stack-work\dist\0a54338c build lib:sdl2-mixer exe:sdl2-mixer-basic exe:sdl2-mixer-basic-jumbled exe:sdl2-mixer-basic-raw exe:sdl2-mixer-basic-raw-2 exe:sdl2-mixer-effect exe:sdl2-mixer-music --ghc-options " -fdiagnostics-color=always"

These errors do not appeal when example executables are not compiled by setting a flag or just removing "executables" from package.yaml.

boletales commented 6 months ago

Update: Moving the "pkg-config-dependencies" section into the "library" solved the building issue. I assume the "pkg-config-dependencies" section passed some undesirable flags to GHC, preprocessor, or linker. b59ce38c19ae07ed235bff34f15a147bf11501cf itself, and an application depends on it builds and works correctly.