Using GnatPro25.2 on Windows 11.
I am attempting what should be a simple compilation. I have 4 withs in my coontrolling GPR file
With winada32
With LibAdaLang
With SharedLibrary1.gpr
With SharedLibrary2.gpr.
Without the shared Libraries the project links without issue as the linker implicitly sets -static-libgcc.
With the shared library projects the linker implicitly sets -shared-libgcc.
This causes LD to fail when attempting to link libgnat.a because it cannot resolve any of the windows socket library symbols (undefined reference to every single symbol!)
I cannot get the linker via any of the ‘switches’ to recognise or accept -allow-shlib-undefined.nor can I get it to accept nor link libws2-32.a (note all of the windows/gnat libraries are in C:Gnatpro\25.2\lib\gcc\x86_64-w64-mingw32\13.3.1 which is the default LD_LIBRARY_PATH set up when you install GnatPro)
Given this is the linker failing to resolve the gnat library symbol references
Any help would be appreciated ..
The Windows socket library is ws2_32.dll. The linker switch is “-lws2_32” I guess you are mixing static and dynamic linking.
It is impossible to say without seeing the gpr-files and scenario variables.
Use GNAT.Sockets instead of direct Windows socket calls. It is portable and safe.
Given its libgnat.a a that is failing to resolve its own symbols, and libgnat.a is ADACORE, and its the linker default script which is determining the linking strategy (auto setting dynamic because of the presence of the shared library gprs ) there is nothing I can do to change this.
The contents of the shared library gprs here is not specifically relevant, it doesn’t build them, they are prebuilt. It needs the gpr so that it doesn’t build them but can resolve the methods contained within the libraries which are pure ADA.
What I need is some mechanism to force the linker to obey its own command line arguments which is what –allow-shlib-undefined should do, at least according to ADACore’s own reference manual for the linker.
Quite relevant. For example, prebuilt library projects must have:
for Externally_Built use "true";
What you need is to understand what is going on. It is completely determined by the gpr-files.
The GPRs fro the share library are correct.. they have no Linker project element (i removed them just to confirm it has no effect) and yes externally built is set to true.
In this case it’s not determined by the GPR files is it? Its the Linker step that is failing, thus its the Linkers own rules, ie the default script it uses which is built into the Linker which is causing the issue. If it ignores pretty much everything that goes into the ‘Switches’ for the linker package then its a Linker issue.
Its the Linker that changes its own rules, based on its own inbuilt script, to use -shared-libgcc and its the Linker which is complaining about every Windows Socket call in libgnat.a (when it reports C:Gnatpro\25.2\lib\gcc\x86_64-w64-mingw32\13.3.1\adalib\\libgnat.a(g-socket.o):g-socket.adb:(.text+0x493):undefined reference to ‘WSAGetLASTError’ its pretty obvious that the issue is with ADACores own libraries) which is an ADACORE supplied library and is the default ADA Library. The Linkers own rules tell it to link libgnat.a, and its own rules set by LD_LIBRARY_PATH which is auto configured by the ADACore installer point at the applicable path as I stated in my original post.
The issue is that the Linker refuses to either link the applicable windows library which is in its own library path or accept that the symbols can be resolved at runtime which as I have stated is what -allow-shlib-undefined should do
Use the -v switch with gprbuild. libgnat.a is perfectly OK. Socket calls are in ws2_32.dll. The linker command should include -lws2_32.
When you use GNAT.Sockets it has in the sources this package (for Windows):
package GNAT.Sockets.Linker_Options is
private
pragma Linker_Options ("-lws2_32");
end GNAT.Sockets.Linker_Options;
This forces the -lws2_32 switch on the linker when you link an application. If that does not happen you have botched your gpr-files, e.g. by linking a library. Again, everything is there.
My Linker switches are -g -v -L.
If finds all my own libraries it wants without issue.
It does NOT add -lws2_32 to the list of libraries it wants to link, so it’s ignoring its own pragma…
So we’re back where we started The linker won’t link a library it needs even if I add -lws2_32 to the linker switches..
One of many possible reasons is wrong target. When linking a library external references are ignored as well as libraries. GCC linker does not support partial linkage.
Until you fix gpr-files it will not work. You cannot fool the GCC linker, at least no so easily.