Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build cava using the MinGW compiler #482

Open
karlstav opened this issue Feb 4, 2023 · 10 comments
Open

build cava using the MinGW compiler #482

karlstav opened this issue Feb 4, 2023 · 10 comments

Comments

@karlstav
Copy link
Owner

karlstav commented Feb 4, 2023

          I made some changes to build cava using the MinGW compiler (basically the commands mentioned in the linux section of Readme): 
diff --git a/Makefile.am b/Makefile.am
index f133e95..b6cb4de 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,13 +3,19 @@ AUTOMAKE_OPTIONS = foreign
 ACLOCAL_AMFLAGS = -I m4
 
 bin_PROGRAMS = cava
-cava_SOURCES = cava.c cavacore.c config.c input/common.c input/fifo.c input/shmem.c \
+cava_SOURCES = cava.c cavacore.c config.c input/common.c \
                output/terminal_noncurses.c output/raw.c output/noritake.c
 cava_CPPFLAGS = -DPACKAGE=\"$(PACKAGE)\" -DVERSION=\"$(VERSION)\" \
            -D_POSIX_SOURCE -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE_EXTENDED \
 	   -DFONTDIR=\"@FONT_DIR@\"
 cava_CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-result -Wno-unknown-warning-option -Wno-maybe-uninitialized -Wno-vla-parameter
 
+if WINDOWS
+    cava_SOURCES += input/winscap.c
+    cava_CFLAGS += -lkernel32 -lole32
+else
+    cava_SOURCES += input/fifo.c
+    cava_SOURCES += input/shmem.c
 if OSX
     cava_CFLAGS += -DNORT
     cava_LDADD =
@@ -18,6 +24,7 @@ else
     cava_font_dir = @FONT_DIR@
     cava_font__DATA = cava.psf
 endif
+endif
 
 if ALSA
     cava_SOURCES += input/alsa.c
diff --git a/cava.c b/cava.c
index c146682..a73fd8e 100644
--- a/cava.c
+++ b/cava.c
@@ -97,7 +97,7 @@ int should_quit = 0;
 // these variables are used only in main, but making them global
 // will allow us to not free them on exit without ASan complaining
 struct config_params p;
-
+#undef SDL
 // general: cleanup
 void cleanup(void) {
     if (output_mode == OUTPUT_NCURSES) {
diff --git a/config.c b/config.c
index a978264..e160936 100644
--- a/config.c
+++ b/config.c
@@ -19,6 +19,7 @@
 #define NUMBER_OF_SHADERS 2
 
 #ifdef _MSC_VER
+#define mkdir(A, B) mkdir(A)
 #include "Windows.h"
 #define PATH_MAX 260
 #define PACKAGE "cava"
diff --git a/configure.ac b/configure.ac
index 9a8b0e7..fe49d55 100644
--- a/configure.ac
+++ b/configure.ac
@@ -212,7 +212,7 @@ AC_CHECK_LIB(SDL2,SDL_Init, have_sdl=yes, have_sdl=no)
           [do not include support for output with sdl_glsl])
       )
       AS_IF([test "x$enable_output_sdl_glsl" != "xno"], [
-      AX_CHECK_GL(have_opengl=yes, have_opengl=no)
+      have_opengl=yes
       if [[ $have_opengl = "yes" ]] ; then
         LIBS="$LIBS $GL_LIBS"
         CPPFLAGS="$CPPFLAGS -DSDL_GLSL $GL_CFLAGS"
@@ -321,6 +321,11 @@ case "${host_os}" in
         AC_MSG_NOTICE([OSX detected])
         build_mac=yes
         ;;
+    mingw*)
+        AC_MSG_NOTICE([Windows detected])
+        AC_DEFINE([_MSC_VER])
+        build_windows=yes
+        ;;
     freebsd*)
         AC_MSG_NOTICE([FreeBSD detected])
         build_linux=yes
@@ -332,6 +337,7 @@ esac
 
 # Pass the conditionals to automake
 AM_CONDITIONAL([LINUX], [test "$build_linux" = "yes"])
+AM_CONDITIONAL([WINDOWS], [test "$build_windows" = "yes"])
 AM_CONDITIONAL([OSX], [test "$build_mac" = "yes"])
 
 
diff --git a/input/winscap.c b/input/winscap.c
index 8738ec9..1c79e06 100644
--- a/input/winscap.c
+++ b/input/winscap.c
@@ -18,6 +18,15 @@
 #define REFTIMES_PER_SEC 10000000
 #define REFTIMES_PER_MILLISEC 10000
 
+#ifndef PKEY_Device_FriendlyName
+
+#undef DEFINE_PROPERTYKEY
+#define DEFINE_PROPERTYKEY(id, a, b, c, d, e, f, g, h, i, j, k, l) \
+	const PROPERTYKEY id = { { a, b, c, { d, e, f, g, h, i, j, k, } }, l };
+
+DEFINE_PROPERTYKEY(PKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 14);
+#endif
+
 // the device change funcitonality is disabled until I figure out how
 // or if to rewrite it to c
 /*
diff --git a/output/terminal_ncurses.c b/output/terminal_ncurses.c
index 7058714..8b50b96 100644
--- a/output/terminal_ncurses.c
+++ b/output/terminal_ncurses.c
@@ -6,6 +6,9 @@
 #include <wchar.h>
 
 #include "util.h"
+#ifdef _MSC_VER
+#include <windows.h>
+#endif
 
 int gradient_size = 64;
 
@@ -310,6 +313,17 @@ int draw_terminal_ncurses(int is_tty, int dimension_value, int dimension_bar, in
 
 // general: cleanup
 void cleanup_terminal_ncurses(void) {
+#ifdef _MSC_VER
+    setecho(1, 1);
+    HANDLE hStdOut = NULL;
+    CONSOLE_CURSOR_INFO curInfo;
+
+    hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
+    GetConsoleCursorInfo(hStdOut, &curInfo);
+    curInfo.bVisible = TRUE;
+    SetConsoleCursorInfo(hStdOut, &curInfo);
+    system("cls");
+#else
     echo();
     system("setfont  >/dev/null 2>&1");
     system("setfont /usr/share/consolefonts/Lat2-Fixed16.psf.gz  >/dev/null 2>&1");
@@ -326,4 +340,5 @@ void cleanup_terminal_ncurses(void) {
     standend();
     endwin();
     system("clear");
+#endif
 }

But I face a huge wall of errors when running make. I don't think they're syntax/semantic errors, they're just redefinition errors:
image

How should I fix this?

Originally posted by @rashil2000 in #479 (comment)

@karlstav
Copy link
Owner Author

karlstav commented Feb 4, 2023

looks like some general difference between linking on linux and MinGW. this maybe related:

https://stackoverflow.com/questions/32547952/multiple-multiple-definition-of-while-compiling-simple-hello-world

@rashil2000
Copy link

Yes, I checked that link - there they seem to be using the -static flag twice which is causing the problem.

@rashil2000
Copy link

rashil2000 commented Feb 11, 2023

For those who want a crack at this, here's what I did in an MSYS2 MINGW64 shell:

First install dependencies:

pacman -S mingw-w64-x86_64-{autotools,gcc,fftw,ncurses} libtool m4 make

Then install iniparser:

cd ~
git clone https://github.com/ndevilla/iniparser
cd iniparser
make
cp libiniparser.a /mingw64/lib/

Then build cava:

cd ~
git clone https://github.com/karlstav/cava
cd cava
git apply ~/fix.patch # the above diff-patch
./autogen.sh
./configure
make

@karlstav
Copy link
Owner Author

had to do

 LIBRARY_PATH=/mingw64/lib C_INCLUDE_PATH=/mingw64/include/  ./configure
 LIBRARY_PATH=/mingw64/lib C_INCLUDE_PATH=/mingw64/include/ make

to find ffiw, could not find ncurses, even though it was installed. maybe some bug in my mingw setup.

also had to remove this thing:

+#define mkdir(A, B) mkdir(A)

why would you add that?

got linking errors, but different:

$  LIBRARY_PATH=/mingw64/lib C_INCLUDE_PATH=/mingw64/include/ make
 cd . && /bin/sh /c/Users/karl/cava/missing automake-1.16 --foreign Makefile
 cd . && /bin/sh ./config.status Makefile depfiles
config.status: creating Makefile
config.status: executing depfiles commands
/bin/sh ./libtool  --tag=CC   --mode=link gcc -std=c99 -Wall -Wextra -Wno-unused-result -Wno-unknown-warning-option -Wno-maybe-uninitialized -Wno-vla-parameter -lkernel32 -lole32  -g -O2   -o cava.exe cava-cava.o cava-cavacore.o cava-config.o input/cava-common.o output/cava-terminal_noncurses.o output/cava-raw.o output/cava-noritake.o input/cava-winscap.o          -lpthread -lm -lfftw3 -liniparser
libtool: link: gcc -std=c99 -Wall -Wextra -Wno-unused-result -Wno-unknown-warning-option -Wno-maybe-uninitialized -Wno-vla-parameter -g -O2 -o .libs/cava.exe cava-cava.o cava-cavacore.o cava-config.o input/cava-common.o output/cava-terminal_noncurses.o output/cava-raw.o output/cava-noritake.o input/cava-winscap.o  -lkernel32 -lole32 -lpthread -lfftw3 -liniparser
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: cava-config.o: in function `MultiplyExtract128':
/usr/include/w32api/winnt.h:1620: multiple definition of `MultiplyExtract128'; cava-cava.o:/usr/include/w32api/winnt.h:1620: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: cava-config.o: in function `UnsignedMultiplyExtract128':
/usr/include/w32api/winnt.h:1629: multiple definition of `UnsignedMultiplyExtract128'; cava-cava.o:/usr/include/w32api/winnt.h:1629: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: cava-config.o: in function `RtlSecureZeroMemory':
/usr/include/w32api/winnt.h:7951: multiple definition of `RtlSecureZeroMemory'; cava-cava.o:/usr/include/w32api/winnt.h:7951: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: cava-config.o: in function `__readgsqword':
/usr/include/w32api/psdk_inc/intrin-impl.h:838: multiple definition of `NtCurrentTeb'; cava-cava.o:/usr/include/w32api/psdk_inc/intrin-impl.h:838: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: cava-config.o: in function `__readgsqword':
/usr/include/w32api/psdk_inc/intrin-impl.h:838: multiple definition of `GetCurrentFiber'; cava-cava.o:/usr/include/w32api/psdk_inc/intrin-impl.h:838: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: cava-config.o: in function `__readgsqword':
/usr/include/w32api/psdk_inc/intrin-impl.h:838: multiple definition of `GetFiberData'; cava-cava.o:/usr/include/w32api/psdk_inc/intrin-impl.h:838: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: output/cava-terminal_noncurses.o: in function `MultiplyExtract128':
/usr/include/w32api/winnt.h:1620: multiple definition of `MultiplyExtract128'; cava-cava.o:/usr/include/w32api/winnt.h:1620: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: output/cava-terminal_noncurses.o: in function `UnsignedMultiplyExtract128':
/usr/include/w32api/winnt.h:1629: multiple definition of `UnsignedMultiplyExtract128'; cava-cava.o:/usr/include/w32api/winnt.h:1629: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: output/cava-terminal_noncurses.o: in function `RtlSecureZeroMemory':
/usr/include/w32api/winnt.h:7951: multiple definition of `RtlSecureZeroMemory'; cava-cava.o:/usr/include/w32api/winnt.h:7951: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: output/cava-terminal_noncurses.o: in function `__readgsqword':
/usr/include/w32api/psdk_inc/intrin-impl.h:838: multiple definition of `NtCurrentTeb'; cava-cava.o:/usr/include/w32api/psdk_inc/intrin-impl.h:838: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: output/cava-terminal_noncurses.o: in function `__readgsqword':
/usr/include/w32api/psdk_inc/intrin-impl.h:838: multiple definition of `GetCurrentFiber'; cava-cava.o:/usr/include/w32api/psdk_inc/intrin-impl.h:838: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: output/cava-terminal_noncurses.o: in function `__readgsqword':
/usr/include/w32api/psdk_inc/intrin-impl.h:838: multiple definition of `GetFiberData'; cava-cava.o:/usr/include/w32api/psdk_inc/intrin-impl.h:838: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: input/cava-winscap.o: in function `MultiplyExtract128':
/usr/include/w32api/winnt.h:1620: multiple definition of `MultiplyExtract128'; cava-cava.o:/usr/include/w32api/winnt.h:1620: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: input/cava-winscap.o: in function `UnsignedMultiplyExtract128':
/usr/include/w32api/winnt.h:1629: multiple definition of `UnsignedMultiplyExtract128'; cava-cava.o:/usr/include/w32api/winnt.h:1629: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: input/cava-winscap.o: in function `RtlSecureZeroMemory':
/usr/include/w32api/winnt.h:7951: multiple definition of `RtlSecureZeroMemory'; cava-cava.o:/usr/include/w32api/winnt.h:7951: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: input/cava-winscap.o: in function `__readgsqword':
/usr/include/w32api/psdk_inc/intrin-impl.h:838: multiple definition of `NtCurrentTeb'; cava-cava.o:/usr/include/w32api/psdk_inc/intrin-impl.h:838: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: input/cava-winscap.o: in function `__readgsqword':
/usr/include/w32api/psdk_inc/intrin-impl.h:838: multiple definition of `GetCurrentFiber'; cava-cava.o:/usr/include/w32api/psdk_inc/intrin-impl.h:838: first defined here
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: input/cava-winscap.o: in function `__readgsqword':
/usr/include/w32api/psdk_inc/intrin-impl.h:838: multiple definition of `GetFiberData'; cava-cava.o:/usr/include/w32api/psdk_inc/intrin-impl.h:838: first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:536: cava.exe] Error 1

@rashil2000
Copy link

rashil2000 commented Feb 13, 2023

You are using the MSYS2 shell (which will build a Cygwin/MSys2 executable).

(Compare the path of ld executable with my screenshots).

You need to use the MINGW64 shell (which will build a Win32 native executable). My changes are w.r.t. the MINGW64 build.

@karlstav
Copy link
Owner Author

hmm don't understand. where and how do i install and run the mingw 64 shell?

@rashil2000
Copy link

When you installed MSYS2, it should have created multiple shortcuts for launching shells - all pertaining to different build systems - MINGW64, MINGW32, CLANG, UCRT, MSYS2 etc. The MINGW64 is the one we need.

@karlstav
Copy link
Owner Author

it is the one I am running. it says MINGW64 on the prompt:

/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: input/cava-winscap.o: in function `__readgsqword':
/usr/include/w32api/psdk_inc/intrin-impl.h:838: multiple definition of `GetFiberData'; cava-cava.o:/usr/include/w32api/psdk_inc/intrin-impl.h:838: first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:536: cava.exe] Error 1

karl@v8-win MINGW64 /c/Users/karl/cava
$

@rashil2000
Copy link

rashil2000 commented Feb 14, 2023

Could you run this command and try again?

pacman -Rcns autotools gcc ncurses binutils

@rashil2000
Copy link

also had to remove this thing:

+#define mkdir(A, B) mkdir(A)

why would you add that?

The mkdir C function takes:

  • two aguments on Unix
  • one argument on Windows, that's why

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants