win32 _decl problems

Fri, 1 Aug 2003 19:26:49 +1000

----- Original Message -----
From: "Fredrik Karlsson" <>
To: <>
Sent: Friday, August 01, 2003 5:09 PM
Subject: win32 _decl problems

> Hi all!
> After browsing through the archives it seems that alot of problems are
> associated with Win32 usage of MP.
> In fact, so does mine. And despite all previous questions and answers I
> still cannot get things going...
> I am using DeltaTrinity's ready-compiled DLL and Visual C++ 6.
> My problems is related to using the functions in my own program.
> After reading some previous posts I understand that I must use _cdecl.
> I have written for example the following:
> extern "C" {
> void _cdecl mpz_init(mpz_t integer);
> void _cdecl mpz_set_str(mpz_t rop, char *str, int base);
> }
> ....
> mpz_set_str(g, gstr, 16);
> The error I get tells me that "second C linkage of overloaded function
> '__gmpz_set_str' not allowed".
> Other error messages I have seen are related to linking - but I assume
> are caused by not properly using the _cdecl.
> So, I do I *properly* use the DLL? Perhaps some samle code?
> I am not a very experienced C-programmer, so please explain in reasonable
> detail if you wish to help me.

If I want to compile a C program using msvc++ 6, my C source would look like
/* File named test.c */
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>

int main () {

/* Declare the variables */
mpz_t num1, num2, num3;

/* Initialise num 1 and num2, and assign a value to them */
mpz_init_set_str(num1, "9999999999999999999999999999", 10);
mpz_init_set_str(num2, "22222222222222222222222233336", 10);

/* Initialise num3 */

/* Set num3 to the sum of num1 and num2 */
mpz_add(num3, num2, num1);

/* Test to see if it might have worked */
if(mpz_cmp(num3, num1) == 1 && mpz_cmp(num3, num2) == 1)
   printf("The addition might have worked");
   else printf("The addition definitely failed");

/* Clear the allocated memory and return 0 */
return 0;


I then run, from the command line:
cl test.c libgmp-3.lib
which produces test.exe - which, when I run it, informs me that the addition
might have worked.

Only problem is, I imagine, that you don't have the static library file

If you had the file 'libgmp-3.dll-def' (which I think Delta Trinity used to
also provide on the ftp site) you could create the static lib by running:
LIB /def:libgmp-3.dll-def

(You need to run that command from a folder that contains both
'libgmp-3.dll' and 'libgmp-3.dll-def'.)

I placed the generated 'libgmp-3.lib' in my MSVC++ compiler's /lib folder so
that it could be found without having to specify any additional directories.

I don't know why Delta Trinity has removed the def file from his ftp site -
I guess there must be other ways of building apps linked to the GMP shared
library, but that's the only way I know.

I'll mail you the def file that I have. I imagine it will be quite
serviceable, but I don't know for sure. At least it will give you something
to try while you're waiting for other advice/help.