icculus / mojoAL

An SDL2-based implementation of OpenAL in a single C file.
https://icculus.org/mojoAL/
zlib License
158 stars 21 forks source link

AL_API and ALC_API cause warnings when building statically with MSVC #21

Closed ericoporto closed 1 year ago

ericoporto commented 1 year ago

mojoAL version : https://github.com/icculus/mojoAL/commit/5db917fd9439f03a36705b4be8673885d8cc9336

compiler : MSVC in VS 2019 16.11.18.

I am getting a bunch of messages like warning LNK4217: locally defined symbol alGetError and so on for thing in the API. The cause seems to be these lines below:

https://github.com/icculus/mojoAL/blob/5db917fd9439f03a36705b4be8673885d8cc9336/mojoal.c#L14-L17

Ideally when building statically, I would like to have empty defines instead.

#define AL_API
#define ALC_API

If there was some preprocessor definition (AL_DLL_EXPORTS or something) for when building mojoal.c as a dll, it could alternate between each possibility.

openal-soft handles this in CMake instead - being a single c file, not sure we want this, but just as well being a single c file I imagine most people just add mojoAL directly in their projects.

(I actually also have other warnings too, but they are for different reasons) ``` mojoal.c(1200): warning C4244: '=': conversion from 'double' to 'float', possible loss of data mojoal.c(1201): warning C4244: '=': conversion from 'double' to 'float', possible loss of data mojoal.c(1202): warning C4244: '=': conversion from 'double' to 'float', possible loss of data mojoal.c(1254): warning C4244: '=': conversion from 'double' to 'ALfloat', possible loss of data mojoal.c(1276): warning C4244: '=': conversion from 'double' to 'ALfloat', possible loss of data mojoal.c(1282): warning C4244: '=': conversion from 'double' to 'int', possible loss of data mojoal.c(1294): warning C4244: '=': conversion from 'double' to 'ALfloat', possible loss of data mojoal.c(1295): warning C4244: '=': conversion from 'double' to 'ALfloat', possible loss of data mojoal.c(1303): warning C4244: '=': conversion from 'const float' to 'int', possible loss of data mojoal.c(1331): warning C4244: '+=': conversion from 'double' to 'ALfloat', possible loss of data mojoal.c(1335): warning C4244: '=': conversion from 'double' to 'ALfloat', possible loss of data mojoal.c(1336): warning C4244: '=': conversion from 'double' to 'ALfloat', possible loss of data mojoal.c(1348): warning C4244: '+=': conversion from 'double' to 'ALfloat', possible loss of data mojoal.c(2935): warning C4028: formal parameter 1 different from declaration mojoal.c(4260): warning C4244: '=': conversion from 'ALfloat' to 'int', possible loss of data mojoal.c(4263): warning C4244: '=': conversion from 'ALfloat' to 'int', possible loss of data ```
icculus commented 1 year ago

Maybe we should #define AL_API only if it isn't already defined?

icculus commented 1 year ago

Wait, if you're using the headers included with mojoAL, you can just #define AL_LIBTYPE_STATIC before including, possibly on the compiler command line, and it'll do what you want; I'll fix mojoal.c to respect that, too.

icculus commented 1 year ago

Okay, latest in revision control should resolve this; build with AL_LIBTYPE_STATIC defined when compiling mojoal.c, and (I think) all the compiler warnings should be resolved.

ericoporto commented 1 year ago

Thank you so much! :)