From: John McCabe on
Hi Guys

Further to my message the other day, I've downloaded the GPL 2009
version of GNAT with the Win32Ada bindings and I'm trying to do
something really simple at the moment, namely, get the number of input
and output midi devices on my system through Win32.Mmsystem.

The code I'm using is at the bottom of this message.

I've created a project in GPS (and other things) but so far have been
unsuccessful in building it and I can't see any obvious reason why.

I've set the project in GPR to reference the [known] win32ada library
and, as far as I can see, there's nothing much different to the
example "connect" application that comes with win32ada however when I
try to build it, I get this (compilation is fine, just linking doesn't
work):

gnatmake -d -PC:\\AdaProjects\\TestMidiDevs\\testmididevs.gpr
MidiDevs.adb
gnatbind -I- -x C:\AdaProjects\TestMidiDevs\mididevs.ali
gnatlink C:\AdaProjects\TestMidiDevs\mididevs.ali
-LC:\GNAT\2009\lib\win32ada\ -lwin32ada -o
C:\AdaProjects\TestMidiDevs\mididevs.exe
c:\adaprojects\testmididevs\MidiDevs.o:MidiDevs.adb:(.text+0x2d):
undefined reference to `_midiInGetNumDevs@0'
c:\adaprojects\testmididevs\MidiDevs.o:MidiDevs.adb:(.text+0x7d):
undefined reference to `_midiOutGetNumDevs@0'
collect2: ld returned 1 exit status
gnatlink: error when calling C:\GNAT\2009\bin\gcc.exe
gnatmake: *** link failed.

[2010-03-05 11:36:33] process exited with status 4 (elapsed time:
02.98s)

Now that says to me that those functions don't exist in the bunch of
libraries that are being linked in. Is there something I need to do to
rebuils the libwin32ada.a? When I installed it I went for the
automatic configuration option and it looked like it was being built
there.

Sorry if this seems like a stupid question but does anyone know what
I've done wrong or what's missing? As I mentioned, it's been a while
since I used Ada in anger so while I'm ok with syntax and semantics,
the subtleties of building something using GPS (tried it in Gnatbench
on Eclipse too) against an existing library are a bit beyond me and
it's difficult to track down much information on that.

Thanks
John

===========
testmididevs.gpr
===========
with "win32ada.gpr";

project TestMidiDevs is

for Source_Dirs use (".");

package Compiler is
for Default_Switches ("ada") use ("-gnat05");
end Compiler;

for Main use ("MidiDevs.adb");

end TestMidiDevs;

==========
MidiDevs.adb
==========
with Ada.Text_IO;

with Win32;
with Win32.Mmsystem;

procedure MidiDevs is

package UINTText_IO is new Ada.Text_IO.Modular_IO(Win32.UINT);

begin
Ada.Text_IO.Put("There are ");
UINTText_IO.Put(Win32.Mmsystem.midiInGetNumDevs);
Ada.Text_IO.Put_Line(" input devices");

Ada.Text_IO.Put("There are ");
UINTText_IO.Put(Win32.Mmsystem.midiOutGetNumDevs);
Ada.Text_IO.Put_Line(" output devices");
end MidiDevs;

From: Dmitry A. Kazakov on
On Fri, 05 Mar 2010 11:41:56 +0000, John McCabe wrote:

> gnatmake -d -PC:\\AdaProjects\\TestMidiDevs\\testmididevs.gpr
> MidiDevs.adb
> gnatbind -I- -x C:\AdaProjects\TestMidiDevs\mididevs.ali
> gnatlink C:\AdaProjects\TestMidiDevs\mididevs.ali
> -LC:\GNAT\2009\lib\win32ada\ -lwin32ada -o
> C:\AdaProjects\TestMidiDevs\mididevs.exe
> c:\adaprojects\testmididevs\MidiDevs.o:MidiDevs.adb:(.text+0x2d):
> undefined reference to `_midiInGetNumDevs@0'
> c:\adaprojects\testmididevs\MidiDevs.o:MidiDevs.adb:(.text+0x7d):
> undefined reference to `_midiOutGetNumDevs@0'
> collect2: ld returned 1 exit status
> gnatlink: error when calling C:\GNAT\2009\bin\gcc.exe
> gnatmake: *** link failed.

You have to link against Winmm.lib change the gpr file as follows:

with "win32ada.gpr";

project TestMidiDevs is

for Source_Dirs use (".");
for Source_Files use ("MidiDevs.adb");
for Main use ("MidiDevs.adb");

package Compiler is
for Default_Switches ("ada") use ("-gnat05");
end Compiler;

package Linker is
for Default_Switches ("ada") use ("-lwinmm");
end Linker;

end TestMidiDevs;

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: John McCabe on
On Fri, 5 Mar 2010 14:12:52 +0100, "Dmitry A. Kazakov"
<mailbox(a)dmitry-kazakov.de> wrote:

<..snip..>

>You have to link against Winmm.lib change the gpr file as follows:
>
>with "win32ada.gpr";
>
>project TestMidiDevs is
>
> for Source_Dirs use (".");
> for Source_Files use ("MidiDevs.adb");
> for Main use ("MidiDevs.adb");
>
> package Compiler is
> for Default_Switches ("ada") use ("-gnat05");
> end Compiler;
>
> package Linker is
> for Default_Switches ("ada") use ("-lwinmm");
> end Linker;
>
>end TestMidiDevs;

Dmitry, you're a star. Thanks for that.

As an aside, now that I've done that, and it works nicely thank you, I
looked at my project properties in GPS and can see no difference to
any of the settings in there. Do you know if there's a way to add that
sort of thing in GPS?

Alternatively, I couldn't see any obvious way to add that sort of
thing in Gnatbench 2.3.x (GPL). Any ideas on that too? I've
importedthe Win32Ada project in to Eclipse and se it as referenced by
the MidiDevs one, but I get Win32 is undefined etc so it's not even
seeing win32.ads!


From: John McCabe on
On Fri, 05 Mar 2010 14:03:31 +0000, John McCabe
<john(a)nospam.assen.demon.co.uk> wrote:

>Alternatively, I couldn't see any obvious way to add that sort of
>thing in Gnatbench 2.3.x (GPL). Any ideas on that too? I've
>importedthe Win32Ada project in to Eclipse and se it as referenced by
>the MidiDevs one, but I get Win32 is undefined etc so it's not even
>seeing win32.ads!

Ok - using the same technique (editing the GPR file) I've now managed
to get the same project working in Eclipse/GNATBench.

Now to see if I can get anywhere with Netbeans!

From: John McCabe on
Hi J-P

>The GUI is just sugar for building the command line. That little box
>shows you the options that will be selected according to the boxes you
>ticked above. In addition (and it is a nice escape for unusual options),
>you can edit that string to add whatever options are not available from
>the GUI.

Yes, I understand that, but I'm used to IDEs where the little boxes
like that have some label that actually explains what they're there
for. It takes the guesswork out of things :-)