From: Maciej Sobczak on
I have a problem writing a proper .gpr file for a project that is
composed of Ada and C++ code and that uses Windows socket API.
I have no problem linking Ada with the C++ library, the problem is
with system library known as Ws2_32.lib.

When compiling a similar project with a C++ compiler, it is enough to
add Ws2_32.lib to the compiler invocation command and it just works.
I cannot, however, find a proper way of doing it with Ada projects.

This is my try (Ws2_32.gpr):

project Ws2_32 is
for Externally_Built use "true";
for Source_Dirs use ();
for Library_Dir use "C:\Program Files\Microsoft SDKs\Windows\v6.0A
\Lib";
for Library_Name use "Ws2_32";
for Library_Kind use "dynamic";
end Ws2_32;

This .gpr file is "withed" by the project file of the final Ada
program. This approach works for my own libraries, but is ineffective
with the system library and gnatlink reports zillions of unresolved
references.

Any feedback is welcome.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com
From: Hibou57 (Yannick Duchêne) on
On 10 fév, 12:13, Maciej Sobczak <see.my.homep...(a)gmail.com> wrote:
> I have a problem writing a proper .gpr file for a project that is
> composed of Ada and C++ code and that uses Windows socket API.
> I have no problem linking Ada with the C++ library, the problem is
> with system library known as Ws2_32.lib.
>
> When compiling a similar project with a C++ compiler, it is enough to
> add Ws2_32.lib to the compiler invocation command and it just works.
> I cannot, however, find a proper way of doing it with Ada projects.

Forgive me if it ever does not fulfill your requirements (you may want
to rely on GPR project files only), here is how I do when I need this
kind of linkage : I put some pragma Linker_Options ("-lkernel32");
pragma Linker_Options ("-lwsock32"); in the private part of
specification files.

Notice the "-l" as a prefix and the lack of any "-Wl,"

If you opt for this solution, make sure you put this in a
specification file which is required by all package which depends on
it (a root package is a good place).
From: Maciej Sobczak on
On 10 Lut, 12:13, Maciej Sobczak <see.my.homep...(a)gmail.com> wrote:

> I have a problem writing a proper .gpr file for a project that is
> composed of Ada and C++ code and that uses Windows socket API.

After struggling a while, I was able to compile everything by hand -
that is, by manually running the GNAT toolchain.
The problem with the use of .gpr files is that in the final incovation
of gnatlink, libraries are listed in the order that comes from the
depth-first traversal of all .gpr files that are connected by "with"
relationships, which leads to unresolved references. The order that I
need is depth-first (or more generally, topologically sorted).

How can I change the order of all dependent libraries that are used in
the final invocation of gnatlink?

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com
From: Maciej Sobczak on
On 10 Lut, 16:21, Maciej Sobczak <see.my.homep...(a)gmail.com> wrote:

> After struggling a while, I was able to compile everything by hand -
> that is, by manually running the GNAT toolchain.
> The problem with the use of .gpr files is that in the final incovation
> of gnatlink, libraries are listed in the order that comes from the
> depth-first traversal of all .gpr files that are connected by "with"
> relationships, which leads to unresolved references. The order that I
> need is depth-first (or more generally, topologically sorted).

What a mess above. :-)

Final update: I was able to get the clean compile with proper order of
"with" clauses in .gpr files. The only curiosity is that libraries are
passed to linker in the order that is *reverse* to the order of
relevant "with" statements.

I'm not sure if that was intended, but as long as I can control the
results, it is just a minor detail.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com
From: Ludovic Brenta on
Maciej Sobczak wrote on comp.lang.ada:
> On 10 Lut, 16:21, Maciej Sobczak <see.my.homep...(a)gmail.com> wrote:
>
> > After struggling a while, I was able to compile everything by hand -
> > that is, by manually running the GNAT toolchain.
> > The problem with the use of .gpr files is that in the final incovation
> > of gnatlink, libraries are listed in the order that comes from the
> > depth-first traversal of all .gpr files that are connected by "with"
> > relationships, which leads to unresolved references. The order that I
> > need is depth-first (or more generally, topologically sorted).
>
> What a mess above. :-)
>
> Final update: I was able to get the clean compile with proper order of
> "with" clauses in .gpr files. The only curiosity is that libraries are
> passed to linker in the order that is *reverse* to the order of
> relevant "with" statements.
>
> I'm not sure if that was intended, but as long as I can control the
> results, it is just a minor detail.

The problem seems a little deeper than that.

with "a";
with "b";
project P is
...
end P;

translates to:

ld -o p p.o -lb -la

which is appropriate if libb.so needs to see the symbols in liba.so.
However, in that case, b.gpr ought to have a with "a"; clause. If
b.gpr lacks the clause, nothing allows the project manager to assume
that libb.so needs liba.so. I suspect that the project manager was
trying to be too clever for its own good; it was potentially hiding a
problem (missing "with a" in b.gpr) while breaking the Law of Least
Astonishment.

I'm not sure whether this is a genuine bug or not. Mmmh. Meditate on
this, I will.

--
Ludovic Brenta.