From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.168.210 with SMTP id e79mr2336064ioj.25.1449560599892; Mon, 07 Dec 2015 23:43:19 -0800 (PST) X-Received: by 10.182.112.135 with SMTP id iq7mr19488obb.10.1449560599827; Mon, 07 Dec 2015 23:43:19 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!mv3no10445491igc.0!news-out.google.com!f6ni16714igq.0!nntp.google.com!mv3no13245235igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 7 Dec 2015 23:43:18 -0800 (PST) In-Reply-To: <220ee60f-3290-43d7-a097-cf90380d8bae@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2a02:120b:7f9:e740:9ac:4adb:7038:36f; posting-account=DQbqYQoAAACn8hHn2LmG2aF7Mhbxl_Lf NNTP-Posting-Host: 2a02:120b:7f9:e740:9ac:4adb:7038:36f References: <220ee60f-3290-43d7-a097-cf90380d8bae@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <26b16c1d-46d5-45ea-92a9-d321fea68716@googlegroups.com> Subject: Re: Using Gnat.Sockets in a Windows DLL From: ahlan@marriott.org Injection-Date: Tue, 08 Dec 2015 07:43:19 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:28699 Date: 2015-12-07T23:43:18-08:00 List-Id: 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 If I have a one line test program that merely initialises a socket, ie My_Socket : GNAT.Sockets.Socket_Type; begin GNAT.Sockets.Create_Socket (My_Socket); then we have no problems building an executable but if we try and use the same lines in a DLL we fail to find the external references. Even if I explicitly put "Pragma Linker_Options ("-lws2_32"); and place libws2_32.a in the Library_Dir Gnat still fails to satisfy the references. I am at a loss as to what I might be doing wrong and what I could try next. This should be easy to solve, it probably has nothing to do with Gnat Sockets but more to do with building DLLs using a GPR file. The following is our Gpr file with "gtkada"; with "win32ada"; project Monitor is package Naming is for Casing use "mixedcase"; end Naming; for Library_Name use "Monitor"; for Shared_Library_Prefix use ""; for Source_Dirs use ("w:\source\ada\interfaces\monitor", "w:\source\ada\interfaces", "w:\source\ada\shared", "w:\source\ada\open\shared"); for Library_Interface use ("Monitor_Interface"); for Object_Dir use "objects"; for Library_Options use ("-Lw:\product\windows", "resources.o"); for Library_Dir use "w:\product\windows"; for Library_Ali_Dir use "d:\binary\ada\interfaces\monitor"; for Library_Kind use "dynamic"; for Library_Standalone use "encapsulated"; package Pretty_Printer is for Default_Switches ("ada") use ("-i2", "-M120", "-aL", "-A1", "-A4"); end Pretty_Printer; package Builder is for Default_Switches ("ada") use ("-s", "-g"); end Builder; package Compiler is for Default_Switches ("ada") use ("-O1", "-gnatQ", "-gnato", "-g", "-gnat12", "-gnatwcehijkmopruvz.c.n.p.t.w.x", "-gnatykmpM120"); end Compiler; package Binder is for Default_Switches ("ada") use ("-E"); end Binder; We build are DLLs using Gprbuild. I