Thanks for all your responses,

The solution is effectively to add the -k flag to dlltool (thanks Luke).
This method is the more basic because it implies to edit the .def and mofy it. But there is no need for anything else than the Windows box and mingw tools.

There is an alternative if  you have the microsoft library by  using the tool reimp (at used to convert microsoft libraries to mingw library.
$ echo "LIBRARY CRYPT32.dll" > crypt32.def
$ echo "EXPORTS" >> crypt32.def
$ reimp -s '.../Crypt32.lib' | sed 's/_//' >> crypt32.def          
$ dlltool  --dllname CRYPT32.dll --def crypt32.def --output-lib libcrypt32.a -k
$ g++  -oaddcert.exe -g -Wno-deprecated addcert.c   ./libcrypt32.a

I tried also to use pexports but this tool does not add the "mangled" name (@nn). For information this mangled name are add to fonctions with PASCAL calling convention (see for more information). So  this tool is not more efficient than impdef.

I also tried a modified version of impdef by Ismael Jurado (1997) intended to add the mangled for PASCAL symbols, but I think that it is buggy because I found that for some @nn  the bytes number (nn) were wrong.

Hope this help someone else.


Luke Dunstan wrote:
It works if you pass the --kill-at (-k) flag to dlltool (after adding the
@nn suffix to each of the names in the .def):

dlltool --kill-at --def crypt32.def --output-lib libcrypt32.a

Luke Dunstan

----- Original Message -----
From: "K.S.Chen" <>
To: "Eric Chastan" <>
Cc: <>
Sent: Monday, July 29, 2002 9:57 AM
Subject: Re: [Mingw-users] HELP NEEDED : link problem

I am not sure what the real problem is.

I run cross-compile in Linux. I uses the to do the conversion.
---begin of

for x ; do
case $x in
*.dll) y=`basename $x .dll` ;;
*) y=$x ;;
/usr/local/bin/pexports $x > $y.def
/usr/local/bin/i586-pc-mingw32-dlltool --dllname $x --def $y.def
--output-lib $y.a
---end of

You can find the crypt32.def in the attachment. I take crypt32.dll from
my Win2K server box. And run the script on my Linux box.
There is no '@N' after each function symbol.

Eric Chastan wrote:

Thanks, I'm sorry for my last question because it was a big mistake
from myself !!

Now I have a very most difficult problem when trying to build a
library from a DLL.

My program is working fine when compiled with borland C++ free tools,
but I would like to use mingw as compilation environment because I'm
using gcc when working under Linux.

My program used the CRYPT32.dll. Unfortunatly the lib libcrypt32.a
given with mingw win32api is not up to date and I need some symbols
undefined in it.
So I must build my own lib file ( I've changed the wincrypt.h to be
able to compile the c file).

I'm using impdef followed by dlltool like this (I get impdef from :

$./impdef c:/WINNT/system32/CRYPT32.dll > crypt32.def
$ dlltool --dllname CRYPT32.dll --def crypt32.def --output-lib
$ g++ -oaddcert.exe -Wno-deprecated addcert.c ./libcrypt32.a
C:\cygwin\tmp/cck9aaaa.o(.text+0xbd8):addcert.c: undefined reference
to `CertNameToStrA@20'
C:\cygwin\tmp/cck9aaaa.o(.text+0xc25):addcert.c: undefined reference
to `CertNameToStrA@20'
C:\cygwin\tmp/cck9aaaa.o(.text+0x1217):addcert.c: undefined reference
to `CertOpenStore@20'
C:\cygwin\tmp/cck9aaaa.o(.text+0x1424):addcert.c: undefined reference
to `CertFindCertificateInStore@24'
C:\cygwin\tmp/cck9aaaa.o(.text+0x1704):addcert.c: undefined reference
to `CertOpenStore@20'
C:\cygwin\tmp/cck9aaaa.o(.text+0x19c9):addcert.c: undefined reference
to `CertFreeCertificateContext@4'
C:\cygwin\tmp/cck9aaaa.o(.text+0x19dd):addcert.c: undefined reference
to `CertFreeCertificateContext@4'
C:\cygwin\tmp/cck9aaaa.o(.text+0x19f3):addcert.c: undefined reference
to `CertCloseStore@8'
C:\cygwin\tmp/cck9aaaa.o(.text+0x1a09):addcert.c: undefined reference
to `CertCloseStore@8'
C:\cygwin\tmp/cck9aaaa.o(.text+0x1baf):addcert.c: undefined reference
to `CertNameToStrA@20'
C:\cygwin\tmp/cck9aaaa.o(.text+0x1bff):addcert.c: undefined reference
to `CertNameToStrA@20'
C:\cygwin\tmp/cck9aaaa.o(.text+0x1d27):addcert.c: undefined reference
to `CertFreeCertificateContext@4'
C:\cygwin\tmp/cck9aaaa.o(.text+0x1d44):addcert.c: undefined reference
to `CertCloseStore@8'
C:\cygwin\tmp/cck9aaaa.o(.text+0x1d85):addcert.c: undefined reference
to `CertFreeCertificateContext@4'
C:\cygwin\tmp/cck9aaaa.o(.text+0x1d9b):addcert.c: undefined reference
to `CertCloseStore@8'

>From this stage I'm editing the .def and adding two things:
1) LIBRARY CRYPT32.DLL at the beginning of the file
2) @NN at the end of each symbols on witch I got an link error (for
example CertCloseStore -> CertCloseStore@8)

Now I restart from dlltool :
$ dlltool --dllname CRYPT32.dll --def crypt32.def --output-lib
$ g++ -oaddcert.exe -Wno-deprecated addcert.c ./libcrypt32.a

All is Ok !!!

But when I run the program I have an error saying that the entry point
CertCloseStore@8 was not found in CRYPT32.dll !!!

Is there someone that allready tried to do something like this ??

Thanks in advance for your advices.

K.S.Chen wrote:

Eric Chastan wrote:

Thanks a lot,

Now I manage to compile my file but I have a problem when liking,
apparently ld can't find any library I give it:

For example I copied the libcrypt32.a from <migwdir>/lib to my
directory and tried to compile (I'm using cygwin) :

$ ls *.c *.o *.a
ls: *.o: No such file or directory
test.c libcrypt32.a
$ g++ -oaddcert.o -c -Wno-deprecated addcert.c
$ ls *.c *.o *.a
test.c test.o libcrypt32.a
$ g++ -otest.exe -Wno-deprecated -L. -l./libcrypt32.a test.c

-L. add current directory to library search path

you should write the command like
$ g++ -otest.exe -Wno-deprecated -L. -lcrypt32 test.c

cannot find -l./libcrypt32.a

Any help ??


Oscar Fuentes wrote:

Eric Chastan <>
<> <>

I'am just begining using mingw and I have the following error when I
try to link my programm:

g++ -oess.exe -Wno-deprecated ess.c
cannot find -lmingwex

I tried to find a file named *mingwex* within my mingw directory but
there is no such file.

Are you using gcc 3.1, by chance? If the answer is yes, you need to
download the libmingwex.a file available on the SF download are, as
explained by the MinGW gcc 3.1 release notes.

If you are using gcc 2.95.x, download the latest MinGW runtime
package. It should contain the necessary files.

The SourceForge download page, as you probably know, is: