This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Linking in WSAGetLastError


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@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@12
   Warning: resolving _mandel_init by linking to _mandel_init@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@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 <windows.h>
#include <stdio.h>

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@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@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@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@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@us.ibm.com


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]