Article View: comp.os.os2.programmer
Article #1769Re: Creating a DLL with GCC 2.2.2
From: Colin Jensen
Date: Sat, 07 Nov 1992 05:09
Date: Sat, 07 Nov 1992 05:09
63 lines
3427 bytes
3427 bytes
In article <Rg1RTB1w165w@dat1hb.north.de> lion@dat1hb.north.de (Daniel Tietze) writes:
>We are currently trying to persuade GCC 2.2.2 (and LINK386, of course) to
>produce a DLL (for experimentation reasons with just one function:
>DebugMsg() ).
>We set up a DEF-File asking LINK386 to EXPORT the function, but this does
>not happen. GCC compiles the stuff OK, but LINK386 says:
> function DebugMsg (alias DebugMSG) : undefined export
>(or something to that effect).
>Now, my question is:
>Given a source module OURDLL.CC and a definition file OURDLL.DEF,
>with a routine "void DebugMsg()" in OURDLL.CC, how do we combine this stuff
>into a DLL with the tools already mentioned?
>AND: How do we import it into, say DLLTEST.CC?
I have not made any DLLs with gcc. But let me add my two cents anyways ;-)
In C++ (as your .cc file implies), function names are mangled greatly
before linking. Basically both the function name, the return type, and
all of the parameter types are encoded into a single name for the function.
The advantage of this name-mangling is that if you define a function
in one file, but mis-declare the function in another file that you use
the function from, you will be prevented from linking your incorrect
program.
The problem is that the .DEF file expects that you are able to name
your function - but you don't know what the mangled name is.
The way around this potential fiasco is to use a gcc extention called
"asm" to tell gcc *exactly* what what you want the function to be named.
For a function declaration like
int *foo(int one, long two);
you can write
int *foo(int one, long two) asm("foo");
to demand that gcc select the name "foo" for the name of the function
to be put into the object file.
Similarly, for a function definition like
int *foo(int one, long two) { return NULL; }
you can write
int *foo(int one, long two) asm("foo") { return NULL; }
So at the very least, you will have to use the asm keyword in both
the DLL source code (for the definition of your function), and
in the source code for the EXE that uses your DLL (for the declaration
of the function).
Note that although I have mentioned only the gnu C++ compiler, the gnu
C compiler has a similar problem in that it insists on putting an
underscore in front of all C symbol names (a good UNIX tradition).
You can either again use the asm keyword to rename C symbols to
remove the underscore (as is done in your os2-include directory that
comes with gcc/2 so go look there for examples), or you can simply
add the underscore into your DEF files and live with it.
I think that if you use EMX and use the OMF output option, emx/gcc
will automatically remove the leading underscores. You will still
need to use asm for C++ source though. [I don't use EMX myself,
so I may be off]
Good luck!
--
Colin Jensen
ljensen@netcom.netcom.com cjensen@ampex.com
Technical Details
Message-ID:
<1992Nov7.050943.18992@netcom.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!stanford.edu!kronos.arc.nasa.gov!iscnvx!netcomsv!netcom.com!ljensenReferences:
<Rg1RTB1w165w@dat1hb.north.de>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.os2.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!stanford.edu!kronos.arc.nasa.gov!iscnvx!netcomsv!netcom.com!ljensen From: ljensen@netcom.com (Colin Jensen) Subject: Re: Creating a DLL with GCC 2.2.2 Message-ID: <1992Nov7.050943.18992@netcom.com> Organization: Netcom - Online Communication Services (408 241-9760 guest) References: <Rg1RTB1w165w@dat1hb.north.de> Date: Sat, 7 Nov 1992 05:09:43 GMT Lines: 63