how to use C++ API in MinGW

for some reason I do not want to use the C API with MinGW 4.9, so I had to make myself an import library for fmod (L). dll, I hope it will be useful.

test example (without error checking):[code]
#include <stdio.h>
#include “fmod.hpp”

int main()
{
FMOD::System *system = NULL;
FMOD::System_Create(&system);

unsigned int version;
system->getVersion(&version);
printf("FMOD lib version %08x founded\n", version);

system->init(512, FMOD_INIT_NORMAL, 0);

system->release();

return 0;

}
[/code]
compiles and see several “undefined reference…”. add key “-Wl, - no-demangle” for linker to see the mangled names of functions: g++ -o main.exe main.cpp -Wl,--no-demangle ... ...undefined reference to `__ZN4FMOD6System10getVersionEPj@8' ...undefined reference to `__ZN4FMOD6System4initEijPv@16' ...undefined reference to `__ZN4FMOD6System7releaseEv@4' ...undefined reference to `_FMOD_System_Create@4'

start fixing it.[list=1][]first get the export table and ordinals of fmod.dll, it needs to use dumpbin utility from Visual Studio: dumpbin /exports fmod.dll > fmod.exports.txt
[/
:m:1tviu5j5]
[*]look at the mangled function: __ZN4[color=#008000]FMOD[/color]6[color=#008000]System[/color]10[color=#008000]getVersion[/color]EPj@8, remember the last value getVersion

[/:m:1tviu5j5]
[
]open fmod.exports.txt and find this value, get something like

[color=#0000FF]185[/color] B8 000B8AD0 ?[color=#008000]getVersion[/color]@[color=#008000]System[/color]@[color=#008000]FMOD[/color]@@QAG?AW4FMOD_RESULT@@PAI@Z

we need only the first number

[/:m:1tviu5j5]
[
]repeat this for all “undefined reference”

[/:m:1tviu5j5]
[
]create a .def file (fmod4gcc.def, for example): LIBRARY "fmod.dll" EXPORTS _ZN4FMOD6System10getVersionEPj@8 @185 NONAME _ZN4FMOD6System4initEijPv@16 @189 NONAME _ZN4FMOD6System7releaseEv@4 @213 NONAME FMOD_System_Create@4 @989 NONAME
[list][]_ZN4FMOD6System10getVersionEPj@8 — this is a mangled name for GCC[/:m:1tviu5j5]
[]@185 — ordinal founded in fmod.exports.txt[/:m:1tviu5j5]
[]NONAME — no names, ordinal only[/:m:1tviu5j5][/list:u:1tviu5j5]
[/:m:1tviu5j5]
[
]now can create an import library: dlltool -d fmod4gcc.def -l libfmod4gcc.a
and add the resulting library: g++ -o main.exe main.cpp -Wl,--no-demangle -L. -lfmod4gcc
[/*:m:1tviu5j5][/list:o:1tviu5j5]

result:[code]

main.exe
FMOD lib version 00010400 founded
[/code]

I do not know whether it is possible to automate this process, manually it takes a lot of time :frowning:
but this method works, I successfully compiled all the examples shipped with the version 1.04.00

I’m amazed that worked, its certainly not the recommended method :slight_smile:
The C++ ABI is usually incompatible between all different compilers, thats why for dll compatibility between compilers we recommend simply using the C functionality.
usually you just use dlltool on the dll , and if it needs a def file, its just a simple list of the C symbols with no mangling.
You are restricted to the C interface though as mentioned.

as I recall, a different ABI does not allow to link the program to the level of binary code. FMOD has no static library, only the external DLL, and the only problem is different calling conventions (gcc vs msvc).

different ABI can not be corrected, but the calling convention can “workaround” using ordinals.

I also can not recommend this method. changing / updating the library will need a lot of manual work, so this method can be considered only as an experiment.