comp.lang.ada
 help / color / mirror / Atom feed
From: ahlan@marriott.org
Subject: Re: Using Gnat.Sockets in a Windows DLL
Date: Thu, 24 Dec 2015 06:46:03 -0800 (PST)
Date: 2015-12-24T06:46:03-08:00	[thread overview]
Message-ID: <cccea45c-c01d-4d01-8238-f57670680632@googlegroups.com> (raw)
In-Reply-To: <220ee60f-3290-43d7-a097-cf90380d8bae@googlegroups.com>

On Thursday, November 26, 2015 at 8:57:02 AM UTC+1, ah...@marriott.org wrote:
> We have windows programs and DLLs that use the Windows WinSock API directly.
> In order to make this code target independent (at least for Linux & OSX) we thought we should convert the code to use Gnat.Sockets.
> This is relatively trivial.
> Or at least it is for programs.
> When we try to convert our DLLs we run into a linker problem.
> If all we do is a "with Gnat.Sockets" then using GprBuild produces lots of messages saying that various entry points could not be found.
> See below.
> I recognize many of them as being in WS2_32.dll - which GprBuild finds when we build our programs (its in Windows/System32)
> Except that the names are not quite right so I suspect that this is the root cause of the problem.
> Has anyone any idea why a build of a DLL should behave differently to a build of a program with respect to name mangling?
> 
> Best wishes,
> Ahlan
> -----------
> 
> gprbuild -d -PD:\Binary\Ada\tools\cal_dll\Cal_Dll.gpr -XWIN32ADA_BUILD=default -XLIBRARY_TYPE=static
> gprlib.exe Cal_Dll.lexch
> gnatbind -n -o b__Cal_Dll.adb -LCal_Dll -a -E D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.ali
> gcc.exe -c -x ada -gnatA -gnatws b__cal_dll.adb -o b__cal_dll.o ...
> gcc.exe -shared -static-libgcc -o W:\product\windows\Cal_Dll.dll D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.o ...
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1b46): undefined reference to `gethostname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1c9c): undefined reference to `getpeername@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x2323): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x3518): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x1c): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x246): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x27f): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x109): undefined reference to `_imp__getservbyname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x159): undefined reference to `_imp__getservbyport@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x2a4): undefined reference to `__WSAFDIsSet@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x34c): undefined reference to `_imp__ioctlsocket@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x3b4): undefined reference to `_imp__WSAStringToAddressA@20'
> collect2.exe: error: ld returned 1 exit status
> gprlib: c:\gnatpro\7.3.1\bin\gcc execution error
> gprbuild: could not build library for project cal_dll
> [2015-11-26 08:36:34] process exited with status 4, 100% (36/36), elapsed time: 01.67s


To summarise: We want to build an encapsulated DLL so that we don't have to distribute the Ada Runtime etc. AdaCore define an encapsulated library as only depending on system libraries.
However I wonder what is meant by system libraries.
We can successfully link if we restrict ourselves coroutines defined in Win32
In our gpr we "with Win32ada;" and can link Winsock routines
however if we try to use Gnat.Sockets the link fails to find entry points such as gethostname@8
this entry point is defined in libws2_32.a but all our attempts to provide this static library seem to be ignored.
We have tried pragma linker_options and specifying the file using "for linker_Options use" in the project gpr.
I have even tried making a library project gpr file with the sole purpose of defining where libws2_32.a can be found.
I suspect therefore that encapsulated libraries somehow "know" what libraries are "system libraries" and ignores all attempts to include others.
Which therefore begs the question as to how I can add Ws2_32 to this list of known libraries.
Surely Ws2_32 is as much a system library as WinSock?
so why should encapsulated libraries be able to use Winsock and not Ws2_32?
Any ideas anyone?


  parent reply	other threads:[~2015-12-24 14:46 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-26  7:56 Using Gnat.Sockets in a Windows DLL ahlan
2015-11-26  8:39 ` Dmitry A. Kazakov
2015-12-08  7:43 ` ahlan
2015-12-08  9:52   ` Dmitry A. Kazakov
2015-12-09  7:20 ` ahlan
2015-12-09  9:20   ` Dmitry A. Kazakov
2015-12-09 12:02 ` ahlan
2015-12-09 12:33   ` Dmitry A. Kazakov
2015-12-09 15:06 ` ahlan
2015-12-09 15:58   ` Dmitry A. Kazakov
2015-12-09 19:11   ` Simon Wright
2015-12-11 17:53 ` ahlan
2015-12-12 12:47   ` Simon Wright
2015-12-12 19:44     ` ahlan
2015-12-12 20:38       ` Simon Wright
2015-12-24 14:46 ` ahlan [this message]
2015-12-25 11:09   ` Simon Wright
2016-01-13 20:25 ` ahlan.marriott
2016-04-20 17:10   ` Dmitry A. Kazakov
2016-04-23  9:24     ` ahlan.marriott
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox