mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
3.93k stars 347 forks source link

Fails to compile on MSYS/MinGW #648

Closed Dr-42 closed 1 year ago

Dr-42 commented 1 year ago
[ERROR] Stderr: In file included from ./src/main.cpp:4: ./src/include/miniaudio.h: In function 'ma_result ma_context_create_IMMDeviceEnumerator__wasapi(ma_context*, ma_IMMDeviceEnumerator*)': ./src/include/miniaudio.h:20111:37: error: cannot convert 'const IID' {aka 'const GUID'} to 'const IID' {aka 'const GUID*'} in argument passing 20111 #define MA_CLSID_MMDeviceEnumerator MA_CLSID_MMDeviceEnumerator_Instance ^~~~~~~~
const IID {aka const GUID}
./src/include/miniaudio.h:19736:148: note: in definition of macro 'ma_CoCreateInstance' 19736 #define ma_CoCreateInstance(pContext, rclsid, pUnkOuter, dwClsContext, riid, ppv) ((MA_PFN_CoCreateInstance)pContext->win32.CoCreateInstance)(rclsid, pUnkOuter, dwClsContext, riid, ppv) ^~ ./src/include/miniaudio.h:21295:40: note: in expansion of macro 'MA_CLSID_MMDeviceEnumerator' 21295 hr = ma_CoCreateInstance(pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator); ^~~~~~~ ./src/include/miniaudio.h: In function 'ma_result ma_context_get_MMDevice__wasapi(ma_context, ma_device_type, const ma_device_id, ma_IMMDevice*)': ./src/include/miniaudio.h:20111:37: error: cannot convert 'const IID' {aka 'const GUID'} to 'const IID' {aka 'const GUID*'} in argument passing 20111 #define MA_CLSID_MMDeviceEnumerator MA_CLSID_MMDeviceEnumerator_Instance ^~~~~~~~
const IID {aka const GUID}
./src/include/miniaudio.h:19736:148: note: in definition of macro 'ma_CoCreateInstance' 19736 #define ma_CoCreateInstance(pContext, rclsid, pUnkOuter, dwClsContext, riid, ppv) ((MA_PFN_CoCreateInstance)pContext->win32.CoCreateInstance)(rclsid, pUnkOuter, dwClsContext, riid, ppv) ^~ ./src/include/miniaudio.h:21369:40: note: in expansion of macro 'MA_CLSID_MMDeviceEnumerator' 21369 hr = ma_CoCreateInstance(pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator); ^~~~~~~ ./src/include/miniaudio.h: In function 'ma_result ma_context_enumerate_devices__wasapi(ma_context, ma_enum_devices_callback_proc, void)': ./src/include/miniaudio.h:20111:37: error: cannot convert 'const IID' {aka 'const GUID'} to 'const IID' {aka 'const GUID'} in argument passing 20111 #define MA_CLSID_MMDeviceEnumerator MA_CLSID_MMDeviceEnumerator_Instance ^~~~~~~~
const IID {aka const GUID}
./src/include/miniaudio.h:19736:148: note: in definition of macro 'ma_CoCreateInstance' 19736 #define ma_CoCreateInstance(pContext, rclsid, pUnkOuter, dwClsContext, riid, ppv) ((MA_PFN_CoCreateInstance)pContext->win32.CoCreateInstance)(rclsid, pUnkOuter, dwClsContext, riid, ppv) ^~ ./src/include/miniaudio.h:21747:40: note: in expansion of macro 'MA_CLSID_MMDeviceEnumerator' 21747 hr = ma_CoCreateInstance(pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator); ^~~~~~~ ./src/include/miniaudio.h: In function 'ma_result ma_device_init__wasapi(ma_device, const ma_device_config, ma_device_descriptor, ma_device_descriptor)': ./src/include/miniaudio.h:20111:37: error: cannot convert 'const IID' {aka 'const GUID'} to 'const IID' {aka 'const GUID'} in argument passing 20111 #define MA_CLSID_MMDeviceEnumerator MA_CLSID_MMDeviceEnumerator_Instance ^~~~~~~~
const IID {aka const GUID}

./src/include/miniaudio.h:19736:148: note: in definition of macro 'ma_CoCreateInstance' 19736 | #define ma_CoCreateInstance(pContext, rclsid, pUnkOuter, dwClsContext, riid, ppv) ((MA_PFN_CoCreateInstance)pContext->win32.CoCreateInstance)(rclsid, pUnkOuter, dwClsContext, riid, ppv) | ^~ ./src/include/miniaudio.h:22676:49: note: in expansion of macro 'MA_CLSID_MMDeviceEnumerator' 22676 | hr = ma_CoCreateInstance(pDevice->pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator); | ^~~~~~~

mackron commented 1 year ago

Thanks. These should be fixed in the dev branch. Are you able to give that a try?

Dr-42 commented 1 year ago

Yes yes. The dev branch works perfectly. Thank you so much

PietroCarrara commented 1 year ago

Confirming this to be mostly fixed: I still get one error for not having strcasecmp defined.

include\miniaudio.h: In function 'ma_bool32 ma_path_extension_equal(const char*, const char*)':
    line 64088: error: 'strcasecmp' was not declared in this scope

include\miniaudio.h: In function 'ma_bool32 ma_path_extension_equal_w(const wchar_t*, const wchar_t*)':
    Line 64129: error: 'strcasecmp' was not declared in this scope

This install is from my university's computers, so I don't have much info beyond this:

C:> mingw32-g++ -v
Using built-in specs.
COLLECT_GCC=mingw32-g++
COLLECT_LTO_WRAPPER=C:/Program\ Files\ (x86)/CodeBlocks/MinGW/bin/../libexec/gcc/mingw32/5.1.0/lto-wrapper.exe
Target: mingw32
Configured with: ../../../src/gcc-5.1.0/configure --build=mingw32 --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-libgomp --enable-lto --enable-graphite --enable-libstdcxx-debug --enable-threads=posix --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libstdcxx-threads --enable-libstdcxx-time --with-gnu-ld --disable-werror --disable-nls --disable-win32-registry --disable-symvers --enable-cxx-flags='-fno-function-sections -fno-data-sections -DWINPTHREAD_STATIC' --prefix=/mingw32tdm --with-local-prefix=/mingw32tdm --with-pkgversion=tdm-1 --enable-sjlj-exceptions --with-bugurl=http://tdm-gcc.tdragon.net/bugs
Thread model: posix
gcc version 5.1.0 (tdm-1)

It's "fixable" by having a #define strcasecmp strcmp before #include <miniaudio.h>, but I'm sure this will produce errors down the line.

orcmid commented 1 year ago

You should include

#include <strings.h>

It is a POSIX-standard function. It is supported on Linux, but it does not appear to be included in the ISO C Standard. So if strings.h does not get it for you, your fix may be necessary.

In the second error report, there is something even stranger. It looks like it should be a wchar_t string comparison.

With luck, you might not actually be using the ma_path_extension_equal( ), and especially ma_path_extension_equal_w( ) functions directly or indirectly in your use of miniaudio. :).

PietroCarrara commented 1 year ago

Yeah, strcasecmp is not defined in strings.h provided by mingw's gcc. So, #defineing our way we go! Thank you for the quick response!

mackron commented 1 year ago

This is a strange one because I use MinGW and I'm not getting such errors. What version of MinGW are you using?

PietroCarrara commented 1 year ago

I know it's really old, tomorrow I'll go to the labs and get more specific

PietroCarrara commented 1 year ago

The mingw version installed is the one that comes bundled with Code::Blocks 17.12 for windows.

it comes with mingw32-gcc and mingw32-g++ at version (tdm-1) 5.1.0, and gcc and g++ at 4.4.3 (although I don't know the difference between mingw32-gcc and gcc)

Also, looked up what strings.h looked like:

/*
    File: strings.h
    Copyright: Public Domain

    This file is provided because non ANSI fuctions are described in string.h 
    that belong in strings.h.  These functions are provided for in the OLDNAME
    libraries.
*/
#if !defined(_STRINGS_H_)
# define _STRINGS_H_ 1
# include <string.h>
#endif

That is the whole file. Looking at , the strcasecmp is contained within some conditionals:

#ifndef _STRING_H_
...
#ifndef RC_INVOKED
...
#ifndef __STRICT_ANSI__
...
#ifndef _NO_OLDNAMES
...
int __cdecl __MINGW_NOTHROW strcasecmp (const char*, const char *);
mackron commented 1 year ago

Does your compiler support _stricmp()? I could perhaps make it so your compiler uses that instead of strcasecmp(), but since I don't have a practical way to reproduce it on my computer it would depend on your or someone in the community advising me on the specific set of conditions I would need to check for.

What is the command you're using to compile by the way? I do have a copy of TDM 64-bit installed and it's GCC version 5.1.0. I could try replicating on that perhaps.

PietroCarrara commented 1 year ago

main.cpp:

#include <stdio.h>

#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"

int main(int argc, char** argv)
{
    ma_result result;
    ma_engine engine;

    if (argc < 2) {
        printf("No input file.");
        return -1;
    }

    result = ma_engine_init(NULL, &engine);
    if (result != MA_SUCCESS) {
        printf("Failed to initialize audio engine.");
        return -1;
    }

    ma_engine_play_sound(&engine, argv[1], NULL);

    printf("Press Enter to quit...");
    getchar();

    ma_engine_uninit(&engine);

    return 0;
}

To compile: > mingw32-g++.exe -Wall -Wno-unused-function -Wall -std=c++11 -g -c main.cpp

I've now noticed that if I remove the C++11 argument it compiles successfully. On Linux I'm able to compile using C++11.

On _stricmp, it's the same, only available when I disable C++11.

mackron commented 1 year ago

Thanks. I tried with my version of TDM and cannot replicate it. This is the command line I used: C:\TDM-GCC-64\bin\g++ ../simple_playback.c -o bin/simple_playback -Wall -Wno-unused-function -std=c++11 -g

This is the kind of situation where I'd have to lean on the community to give me a suggestion on how to work around it.