Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Importance: Normal Subject: Re: Linking in WSAGetLastError To: DJ Delorie Cc: cygwin AT sourceware DOT cygnus DOT com X-Mailer: Lotus Notes Release 5.0.3 (Intl) 21 March 2000 Message-ID: From: "Ed Bradford/Raleigh/IBM" Date: Wed, 27 Sep 2000 12:54:20 -0400 X-MIMETrack: Serialize by Router on D04NMS90/04/M/IBM(Release 5.0.3 (Intl)|21 March 2000) at 09/27/2000 12:54:21 PM MIME-Version: 1.0 Content-type: text/plain; charset=us-ascii Ooops, I copy/pasted the line from the URL you sent. That line has a "-s" in it. Below is the marked up text from the URL. Chages are in RED if the color gets through all the email servers and clients. I changed the "mydll" to mandel_dll for my example and the "-s" in the first, third and fifth gcc lines to " -shared". The "-shared" works. The first dlltool line produces a "no .def file" error. Creating a .def file that looks like EXPORTS mandel mandel_init quiets dlltool. The third line (the second call to gcc) line produces (if the "-s" is changed to "-shared"): Warning: resolving _mandel_init by linking to _mandel_init AT 12 Use --enable-stdcall-fixup to disable these warnings Use --disable-stdcall-fixup to disable these fixups This is just a warning. The forth line (the second call of dlltool) succeeds quietly. The fifth line (the third call to gcc) fails with the following message: ~/src/cyg $ gcc -Wl,mandel_dll.exp -o mandel_dll.dll mandel_dll.o -Wl, -e,_mandel_init AT 12 Warning: resolving _mandel_init by linking to _mandel_init AT 12 Use --enable-stdcall-fixup to disable these warnings Use --disable-stdcall-fixup to disable these fixups /usr/lib/libcygwin.a(libcmain.o)(.text+0x6a):libcmain.c: undefined reference to `WinMain AT 16' collect2: ld returned 1 exit status If "-shared" is added, the fifth line succeeds with a the same warning as in the second gcc call. The sixth line (the third and final call to dlltool) succeeds quietly. If the following program is used as a test: ============mandel.c========================== #include #include int main(int ac, char *av[]) { double a,b,c,d; double x,y,x1,y1; unsigned long iterations; DWORD starttime, endtime; int i; iterations = 100000000; if(ac != 5) { a = .1; b = .1; c = .1; d = .1; } else { a = atof(av[1]); b = atof(av[2]); c = atof(av[3]); d = atof(av[4]); if(ac > 5) iterations = atoi(av[5]); } starttime = GetTickCount(); i = mandel(a,b,c,d,iterations); endtime = GetTickCount(); printf("mandel(%13.9f %13.9f %13.9f %13.9f) iter=%u time %f seconds\n", a,b,c,d,i,(double)((endtime - starttime)/1000.)); return 0; } ============mandel.c========================== the following produces a real program: gcc -c mandel.c gcc mandel.o mandel_dll.a On my system, running it with the default floating point values of .1, .1, .1, .1 takes about 38 seconds. (233MHZ Thinkpad). Note, the gcc lines have no optimization specified. Ed ========================================================================== OK, let's go through a simple example of how to build a dll. For this example, we'll use a single file mandel.c for the program (myprog.exe) and a single file mydll.c for the contents of the dll (mydll.dll). Now compile everything to objects: gcc -c mandel.c gcc -c mandel_dll.c Create a .def file that looks like EXPORTS mandel mandel_init Unfortunately, the process for building a dll is, well, convoluted. You have to run five commands, like this: gcc -shared -Wl,--base-file,mandel_dll.base -o mandel_dll.dll mandel_dll.o -Wl,-e,_mandel_init AT 12 dlltool --base-file mandel_dll.base --def mandel_dll.def --output-exp mandel_dll.exp --dllname mandel_dll.dll gcc -shared -Wl,--base-file,mandel_dll.base,mandel_dll.exp -o mandel_dll .dll mandel_dll.o -Wl,-e,_mandel_dll_init AT 12 dlltool --base-file mandel_dll.base --def mandel_dll.def --output-exp mandel_dll.exp --dllname mandel_dll.dll gcc -shared -Wl,mandel_dll.exp -o mandel_dll.dll mandel_dll.o -Wl,-e,_ mandel_init AT 12 The extra steps give dlltool the opportunity to generate the extra sections (exports and relocation) that a dll needs. After this, you build the import library: dlltool --def mandel_dll.def --dllname mandel_dll.dll --output-lib mandel_dll.a Now, when you build your program, you link against the import library: gcc -o mandel mandel.o mandel_dll.a This should succeed. ========================================================================== Note that we linked with -e _mydll_init AT 12. This tells the OS what the DLL's "entry point" is, and this is a special function that coordinates bringing the dll to life withing the OS. The minimum function looks like this: Your Windows 2000 Arborist T/L 589-4410; Outside: 1-919-993-4410 egb AT us DOT ibm DOT com -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com