This is a total shot in the dark and it’s probably a waste of time asking, but you never know. I am using GNAT Studio Community 2021 (Ada2012) and trying to get an audio library to work. I am well aware there are zero audio libraries written exclusively in Ada, so of course it’s a mix of C, C++ with some Ada sample code.
What I have done so far:
Included all the directories I needed.
Ticked the "Language" box under "Project Properties" to include the usage of C and C++ files to make them visible.
C/P the required DLL’s (included in the Audio library folder) into the "src" directory of my project.
So far, with everything above done it DOES compile, so I am half way to getting it to work. However, I get a slew of Linker errors, which seem to be referring to functions (they are C/C++ ones, not Ada) that are missing. This is despite me including all the relevant files and making them visible.
Here is what the compiler comes out with (I’ve cropped it from the first line as the rest is just a continuation with missing function defs from the same object file).
Compile [Ada] main.adb Bind [gprbind] main.bexch
[Ada] main.ali Link [link] main.adb
libamos.a(oal.o):oal.cpp:(.text+0x10): undefined reference to
__imp_alcOpenDevice' c:/gnat/2021/bin/../libexec/gcc/x86_64-w64-mingw32/10.3.1/ld.exe: libamos.a(oal.o):oal.cpp:(.text+0x4c): undefined reference to__imp_alcCreateContext’
Here is the code I wrote to test if everything works.
with al_h; with alc_h; with snd; with snd4ada; with sndloop; procedure Main is begin null; end Main;
For reference, here is the working code that comes with the library.
with text_io; use text_io; with snd4ada; with interfaces.c; with interfaces.c.strings; with ada.command_line; procedure one is -- plays WAV file given on command line subtype glint is interfaces.c.int; linestr: string(1..80); last: natural; music: glint; begin if ada.command_line.argument_count = 1 then declare title : string := Ada.Command_Line.Argument(1); begin --declare snd4ada.initSnds; music:=snd4ada.initLoop( interfaces.c.Strings.New_string(title)); put_line("Hit <enter> to begin"); get_line(linestr,last); snd4ada.playLoop(music); put_line("hit <enter> to end"); get_line(linestr,last); snd4ada.stopLoop(music); snd4ada.termSnds; end; --declare end if; end one;
My guess is the problem is due to a Linker switch perhaps that I need to toggle under the project settings, so it can bind the C,C++ and Ada code together.
Am I just fighting a lost cause here? I would love to get this to work, and it seems my only problem is telling the linker where the declarations are (even though I have included all the relevant files into the project path).
If anyone can help, I would be hugely happy. If I knew how I would write my own Audio Library for Ada, but it seems third party is the only way to go. BTW – I did try to get BASS to work but that’s a no go. This one is the closest to working – and it’s annoying as the sample code produces an .exe that does indeed work. So it must be something I am doing wrong with the Linker.
Source: Windows Questions C++