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

mingw support #58

Closed
tresf opened this issue Mar 5, 2016 · 16 comments
Closed

mingw support #58

tresf opened this issue Mar 5, 2016 · 16 comments
Milestone

Comments

@tresf
Copy link

tresf commented Mar 5, 2016

I've started this via: master...tresf:master

cd libsoundio
mkdir build out; cd build
export MINGW_ARCH=32 # defaults to 64
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/MingwToolchain.cmake \
-DCMAKE_INSTALL_PREFIX=../out
make install

I'm not a C/C++ programmer, so I'm having difficulties with the compilation issues. I'm sure these are all very basic. Help appreciated...

Scanning dependencies of target libsoundio_shared
[  3%] Building C object CMakeFiles/libsoundio_shared.dir/src/soundio.c.obj
[  6%] Building C object CMakeFiles/libsoundio_shared.dir/src/util.c.obj
[  9%] Building C object CMakeFiles/libsoundio_shared.dir/src/os.c.obj
[ 12%] Building C object CMakeFiles/libsoundio_shared.dir/src/dummy.c.obj
[ 15%] Building C object CMakeFiles/libsoundio_shared.dir/src/channel_layout.c.obj
[ 18%] Building C object CMakeFiles/libsoundio_shared.dir/src/ring_buffer.c.obj
Linking C shared library libsoundio.dll
CMakeFiles/libsoundio_shared.dir/objects.a(soundio.c.obj):soundio.c:(.data+0x14): undefined reference to `soundio_wasapi_init'
collect2: error: ld returned 1 exit status
make[2]: *** [libsoundio.dll] Error 1
make[1]: *** [CMakeFiles/libsoundio_shared.dir/all] Error 2
make: *** [all] Error 2
@andrewrk
Copy link
Owner

andrewrk commented Mar 5, 2016

That missing symbol is provided by soundio.c which is compiled into soundio.c.obj, which it looks like you are producing. Can you provide the output of make clean && make VERBOSE=1?

@andrewrk
Copy link
Owner

andrewrk commented Mar 5, 2016

Also can you show the contents of config.h?

@tresf
Copy link
Author

tresf commented Mar 5, 2016

Can you provide the output of make clean && make VERBOSE=1?

https://gist.github.com/tresf/c6ec7a3f7939d351e433

Also can you show the contents of config.h?

/*
 * Copyright (c) 2015 Andrew Kelley
 *
 * This file is part of libsoundio, which is MIT licensed.
 * See http://opensource.org/licenses/MIT
 */

#ifndef SOUNDIO_CONFIG_H
#define SOUNDIO_CONFIG_H

#define SOUNDIO_VERSION_MAJOR 1
#define SOUNDIO_VERSION_MINOR 1
#define SOUNDIO_VERSION_PATCH 0
#define SOUNDIO_VERSION_STRING "1.1.0"

/* #undef SOUNDIO_HAVE_JACK */
/* #undef SOUNDIO_HAVE_PULSEAUDIO */
/* #undef SOUNDIO_HAVE_ALSA */
/* #undef SOUNDIO_HAVE_COREAUDIO */
/* #undef SOUNDIO_HAVE_WASAPI */

#endif

Your config.h question made me wonder if ${CMAKE_BINARY_DIR} needed to be added to includes and/or linking, since it's exporting to the ./build directory, but when I tried adding them in the toolchain, it continues to error in the same place.

@andrewrk
Copy link
Owner

andrewrk commented Mar 5, 2016

Hmm I don't think configure step was successful. SOUNDIO_HAVE_WASAPI should be defined on Windows. Can you show the output of the cmake step?

@andrewrk
Copy link
Owner

andrewrk commented Mar 5, 2016

Your config.h question made me wonder if ${CMAKE_BINARY_DIR} needed to be added to includes

it is, here: https://github.com/andrewrk/libsoundio/blob/master/CMakeLists.txt#L180

@tresf
Copy link
Author

tresf commented Mar 5, 2016

It appears that the find package scripts don't look in the default mingw include directories. I added them for now, but if there's a better way to do this (such as add it directly to the modules), let me know and I'll add it to a PR.

Next, I hit this error which I could not resolve unless I disabled -Wall. I tried to explicitly add -Wmissing-braces but naturally, it would get ignored when -Wall came through.

Here's the latest fixes which enable WASAPI as well as PortAudio (scratch that, sorry), probably ready for a pull request. 731d5ed

@tresf
Copy link
Author

tresf commented Mar 5, 2016

And the build log, for reference...

tres@ubuntu-1204:~/Desktop/libsoundio/build$ rm -rf ../build; mkdir ../build; cd ../build; export MINGW_ARCH=32; cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/MingwToolchain.cmake -DCMAKE_INSTALL_PREFIX=../out; make install
-- The C compiler identification is GNU
-- Check for working C compiler: /opt/mingw32/bin/i686-w64-mingw32-gcc
-- Check for working C compiler: /opt/mingw32/bin/i686-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
Configuring libsoundio version 1.1.0
-- Looking for include files CMAKE_HAVE_PTHREAD_H
-- Looking for include files CMAKE_HAVE_PTHREAD_H - found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE 
-- Could NOT find JACK (missing:  JACK_LIBRARY JACK_INCLUDE_DIR) 
-- Could NOT find PULSEAUDIO (missing:  PULSEAUDIO_LIBRARY PULSEAUDIO_INCLUDE_DIR) 
-- Could NOT find ALSA (missing:  ALSA_LIBRARY ALSA_INCLUDE_DIR) 
-- Could NOT find COREAUDIO (missing:  COREAUDIO_LIBRARY) 
-- Found WASAPI: /opt/mingw32/include 

Installation Summary
--------------------
* Install Directory            : /home/tres/Desktop/libsoundio/out
* Build Type                   : Debug
* Build static libs            : ON
* Build examples               : ON
* Build tests                  : ON

System Dependencies
-------------------
* threads                      : OK
* JACK       (optional)        : not found
* PulseAudio (optional)        : not found
* ALSA       (optional)        : not found
* CoreAudio  (optional)        : not found
* WASAPI     (optional)        : OK

-- Configuring done
-- Generating done
-- Build files have been written to: /home/tres/Desktop/libsoundio/build
Scanning dependencies of target libsoundio_shared
[  2%] Building C object CMakeFiles/libsoundio_shared.dir/src/soundio.c.obj
[  5%] Building C object CMakeFiles/libsoundio_shared.dir/src/util.c.obj
[  8%] Building C object CMakeFiles/libsoundio_shared.dir/src/os.c.obj
[ 10%] Building C object CMakeFiles/libsoundio_shared.dir/src/dummy.c.obj
[ 13%] Building C object CMakeFiles/libsoundio_shared.dir/src/channel_layout.c.obj
[ 16%] Building C object CMakeFiles/libsoundio_shared.dir/src/ring_buffer.c.obj
[ 18%] Building C object CMakeFiles/libsoundio_shared.dir/src/wasapi.c.obj
Linking C shared library libsoundio.dll
[ 18%] Built target libsoundio_shared
Scanning dependencies of target backend_disconnect_recover
[ 21%] Building C object CMakeFiles/backend_disconnect_recover.dir/test/backend_disconnect_recover.c.obj
Linking C executable backend_disconnect_recover.exe
[ 21%] Built target backend_disconnect_recover
Scanning dependencies of target latency
[ 24%] Building C object CMakeFiles/latency.dir/test/latency.c.obj
[ 27%] Building C object CMakeFiles/latency.dir/src/soundio.c.obj
[ 29%] Building C object CMakeFiles/latency.dir/src/util.c.obj
[ 32%] Building C object CMakeFiles/latency.dir/src/os.c.obj
[ 35%] Building C object CMakeFiles/latency.dir/src/dummy.c.obj
[ 37%] Building C object CMakeFiles/latency.dir/src/channel_layout.c.obj
[ 40%] Building C object CMakeFiles/latency.dir/src/ring_buffer.c.obj
[ 43%] Building C object CMakeFiles/latency.dir/src/wasapi.c.obj
Linking C executable latency.exe
[ 43%] Built target latency
Scanning dependencies of target libsoundio_static
[ 45%] Building C object CMakeFiles/libsoundio_static.dir/src/soundio.c.obj
[ 48%] Building C object CMakeFiles/libsoundio_static.dir/src/util.c.obj
[ 51%] Building C object CMakeFiles/libsoundio_static.dir/src/os.c.obj
[ 54%] Building C object CMakeFiles/libsoundio_static.dir/src/dummy.c.obj
[ 56%] Building C object CMakeFiles/libsoundio_static.dir/src/channel_layout.c.obj
[ 59%] Building C object CMakeFiles/libsoundio_static.dir/src/ring_buffer.c.obj
[ 62%] Building C object CMakeFiles/libsoundio_static.dir/src/wasapi.c.obj
Linking C static library libsoundio.a
[ 62%] Built target libsoundio_static
Scanning dependencies of target overflow
[ 64%] Building C object CMakeFiles/overflow.dir/test/overflow.c.obj
Linking C executable overflow.exe
[ 64%] Built target overflow
Scanning dependencies of target sio_list_devices
[ 67%] Building C object CMakeFiles/sio_list_devices.dir/example/sio_list_devices.c.obj
Linking C executable sio_list_devices.exe
[ 67%] Built target sio_list_devices
Scanning dependencies of target sio_microphone
[ 70%] Building C object CMakeFiles/sio_microphone.dir/example/sio_microphone.c.obj
Linking C executable sio_microphone.exe
[ 70%] Built target sio_microphone
Scanning dependencies of target sio_record
[ 72%] Building C object CMakeFiles/sio_record.dir/example/sio_record.c.obj
Linking C executable sio_record.exe
[ 72%] Built target sio_record
Scanning dependencies of target sio_sine
[ 75%] Building C object CMakeFiles/sio_sine.dir/example/sio_sine.c.obj
Linking C executable sio_sine.exe
[ 75%] Built target sio_sine
Scanning dependencies of target underflow
[ 78%] Building C object CMakeFiles/underflow.dir/test/underflow.c.obj
Linking C executable underflow.exe
[ 78%] Built target underflow
Scanning dependencies of target unit_tests
[ 81%] Building C object CMakeFiles/unit_tests.dir/test/unit_tests.c.obj
[ 83%] Building C object CMakeFiles/unit_tests.dir/src/soundio.c.obj
[ 86%] Building C object CMakeFiles/unit_tests.dir/src/util.c.obj
[ 89%] Building C object CMakeFiles/unit_tests.dir/src/os.c.obj
[ 91%] Building C object CMakeFiles/unit_tests.dir/src/dummy.c.obj
[ 94%] Building C object CMakeFiles/unit_tests.dir/src/channel_layout.c.obj
[ 97%] Building C object CMakeFiles/unit_tests.dir/src/ring_buffer.c.obj
[100%] Building C object CMakeFiles/unit_tests.dir/src/wasapi.c.obj
Linking C executable unit_tests.exe
[100%] Built target unit_tests
Install the project...
-- Install configuration: "Debug"
-- Installing: /home/tres/Desktop/libsoundio/out/lib/libsoundio.dll.a
-- Installing: /home/tres/Desktop/libsoundio/out/lib/libsoundio.dll
-- Installing: /home/tres/Desktop/libsoundio/out/lib/libsoundio.a
-- Up-to-date: /home/tres/Desktop/libsoundio/out/include/soundio/soundio.h
-- Up-to-date: /home/tres/Desktop/libsoundio/out/include/soundio/endian.h
-- Installing: /home/tres/Desktop/libsoundio/out/bin/sio_sine.exe
-- Installing: /home/tres/Desktop/libsoundio/out/bin/sio_list_devices.exe
-- Installing: /home/tres/Desktop/libsoundio/out/bin/sio_microphone.exe
-- Installing: /home/tres/Desktop/libsoundio/out/bin/sio_record.exe

@tresf
Copy link
Author

tresf commented Mar 5, 2016

Here's the latest fixes which enable WASAPI as well as PortAudio

WASAPI only, sorry got a bit ambitious with that statement, fixed in fork via tresf@2d016bd.

@andrewrk
Copy link
Owner

andrewrk commented Mar 5, 2016

If you build in release mode, which you should do if you're producing a .DLL for shipping with lmms, then it disables -Werror so that -Wall can't prevent the build from working.

According to your cmake output you're building in Debug mode.

@andrewrk
Copy link
Owner

andrewrk commented Mar 5, 2016

-DCMAKE_BUILD_TYPE=Release on the cmake line.

@andrewrk
Copy link
Owner

andrewrk commented Mar 5, 2016

On Windows it's pretty normal to not use PulseAudio (you said PortAudio but I think you meant PulseAudio?). A Windows build of libsoundio that only has the wasapi backend is reasonable.

@tresf
Copy link
Author

tresf commented Mar 6, 2016

f you build in release mode, which you should do if you're producing a .DLL for shipping with lmms, then it disables -Werror so that -Wall can't prevent the build from working.

In the spirit of not crippling mingw builds, I've replaced -Wall and patched the code to compile without that particular warning via tresf@0efcec8#diff-6e80be2ac81bcaea1cd479308e01774bR1185.

In addition, per suggestion, I've made Release default via tresf@0efcec8#diff-6b541fb1767acf98c379276dee2578eeR58

I did have to keep out -Werror-missing-prototypes though, I hope that's ok.
tresf@0efcec8#diff-af3b638bc2a3e6c650974192a53c7291R200

Last, I tested on mingw64 and found a typo. Fixed and squashed.

Next, I'll try on msys2 to see if a Windows machine running mingw can build this. Then issue a pull request.

@tresf
Copy link
Author

tresf commented Mar 6, 2016

Ok, msys2 is configuring now via tresf@ec21e2f.

But now I'm getting an issue importing a header... Here's the message...

[  2%] Building C object CMakeFiles/libsoundio_shared.dir/src/soundio.c.obj
/mingw64/bin/gcc  -Dlibsoundio_shared_EXPORTS -O3 -DNDEBUG @CMakeFiles/libsoundio_shared.dir/includes_C.rsp   -std=c11 -fvisibility=hidden -Wall -Werror=strict-prototypes -Werror=old-style-definition -D_REENTRANT -D_POSIX_C_SOURCE=200809L -o CMakeFiles/libsoundio_shared.dir/src/soundio.c.obj   -c /home/Tres/libsoundio/src/soundio.c
In file included from C:/msys64/home/Tres/libsoundio/src/soundio_private.h:11:0,
                 from C:/msys64/home/Tres/libsoundio/src/soundio.c:8:
+ C:/msys64/home/Tres/libsoundio/src/soundio_internal.h:14:29: fatal error: soundio/soundio.h: No such file or directory
compilation terminated.
CMakeFiles/libsoundio_shared.dir/build.make:55: recipe for target 'CMakeFiles/libsoundio_shared.dir/src/soundio.c.obj' failed
make[2]: *** [CMakeFiles/libsoundio_shared.dir/src/soundio.c.obj] Error 1
make[2]: Leaving directory '/home/Tres/libsoundio/build'
CMakeFiles/Makefile2:192: recipe for target 'CMakeFiles/libsoundio_shared.dir/all' failed
make[1]: *** [CMakeFiles/libsoundio_shared.dir/all] Error 2
make[1]: Leaving directory '/home/Tres/libsoundio/build'
Makefile:116: recipe for target 'all' failed
make: *** [all] Error 2

@tresf
Copy link
Author

tresf commented Mar 6, 2016

Ok, it appears cmake keeps turning CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES=1 via Platform/Windows-GNU.cmake regardless of the setting.

It's a hack, but fixed via:

set(CMAKE_GENERATOR "MSYS Makefiles")

Msys recommends passing -G"MSYS Makefiles" on the command line, but I can't get that switch to work at all.

@hotgloupi, not quite MSVC, but it's a successful compile on Windows nonetheless (#49).

image

@tresf
Copy link
Author

tresf commented Mar 6, 2016

Since I haven't had any push-back on this conceptually, I wrote up a wiki tutorial for building on either Linux or Windows. Any adjustments are welcome as I wrote this mostly from memory.

https://github.com/andrewrk/libsoundio/wiki/Compiling-for-Windows

Of course, the tutorial won't work unless #59 is merged, so anyone trying it out before hand would first have to clone tresf/libsoundio. 👍

@andrewrk andrewrk added this to the 1.1.1 milestone Apr 26, 2016
@andrewrk
Copy link
Owner

Looks like the wiki and README.md are sufficient.

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

No branches or pull requests

3 participants
@andrewrk @tresf and others