GMP使用MinGW在Windows [英] GMP with MinGW on Windows

查看:950
本文介绍了GMP使用MinGW在Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法成功地建立在我的Windows 7(64位计算机)的GMP库。我遵循的步骤是:

  ./配置--enable_cxx --disable静电--enable-共享 -  preFIX =/ C / MinGW的
使
使安装
做检查

所有的测试顺利通过。很显然,我在那里有可能编译和运行程序的GMP点。但是,当我尝试编译下面的程序:

 的#include<&stdlib.h中GT;
#包括LT&;&string.h中GT;
#包括LT&;&stdio.h中GT;
#包括LT&;&gmp.h GT;字符*的progname;无效print_usage_and_exit()
{
    fprintf中(标准错误,用法:%s的-q NNN \\ n,将progname);
    fprintf中(标准错误,用法:%s的NNN ... \\ N的progname);
    出口(-1);
}INT主(INT ARGC,字符** argv的)
{
    mpz_t N;
    INT I;    将progname =的argv [0];    如果(的argc 2)
        print_usage_and_exit();    mpz_init(N);    如果(的argc == 3和;&放大器;的strcmp(的argv [1],-q)== 0)
    {
        如果(mpz_set_str(N,的argv [2],0)!= 0)
            print_usage_and_exit();
        出口(mpz_probab_prime_p(N,25)== 0);
    }    对于(i = 1; I< ARGC,我++)
    {
        INT结果;
        如果(mpz_set_str(N,的argv [I],0)!= 0)
            print_usage_and_exit();
        结果= mpz_probab_prime_p(N,25);
        mpz_out_str(标准输出,10,N);
        如果(结果== 0)
            看跌期权(是合);
        否则,如果(结果== 1)
            看跌期权(是一个可能的素数);
        否则/ *结果== 2 * /
            看跌期权(是素);
    }
    出口(0);
}

使用以下命令:

 的gcc -m32 -lgmp的main.c

我收到以下错误:

  C:\\用户\\亚历克斯\\应用程序数据\\本地的\\ Temp \\ cc2ZHzEt.o:main.c中:(文字+ 0x7f)中的:未定义的参考`_imp____gmpz_init
C:\\用户\\亚历克斯\\应用程序数据\\本地的\\ Temp \\ cc2ZHzEt.o:main.c中:(文字+ 0xc3):未定义的参考`_imp____gmpz_set_str
C:\\用户\\亚历克斯\\应用程序数据\\本地的\\ Temp \\ cc2ZHzEt.o:main.c中:(文字+ 0xe2):未定义的参考`_imp____gmpz_probab_prime_p
C:\\用户\\亚历克斯\\应用程序数据\\本地的\\ Temp \\ cc2ZHzEt.o:main.c中:(文字+ 0x12b):未定义的参考`_imp____gmpz_set_str
C:\\用户\\亚历克斯\\应用程序数据\\本地的\\ Temp \\ cc2ZHzEt.o:main.c中:(文字+ 0x14a):未定义的参考`_imp____gmpz_probab_prime_p
C:\\用户\\亚历克斯\\应用程序数据\\本地的\\ Temp \\ cc2ZHzEt.o:main.c中:(文字+量0x170):未定义的参考`_imp____gmpz_out_str
C:/ MinGW的/ bin中/../ lib中/ GCC / mingw32的/ 4.7.2 /../../../../的mingw32 /斌/ ld.exe:C:\\用户\\亚历克斯\\应用程序数据\\本地\\ TEMP \\ cc2ZHzEt.o:在第`.eh_frame坏RELOC地址为0x20
C:/ MinGW的/ bin中/../ lib中/ GCC / mingw32的/ 4.7.2 /../../../../的mingw32 /斌/ ld.exe:最后一个环节失败:无效操作
collect2.exe:错误:LD返回1退出状态

谁能告诉我在做什么错?我做我的谷歌搜索,和几个太多时间后,你可以提供任何帮助将是AP preciated。谢谢!


解决方案

  

的-l选项用于库添加到您的程序。注意
  顺序很重要!你应该总是列出库后,所有的
  对象。


尝试的gcc -m32的main.c -lgmp

I managed to build the GMP library successfully on my Windows 7 (64-bit computer). The steps I followed were:

./configure --enable_cxx --disable-static --enable-shared --prefix="/c/MinGW"
make
make install
make check

All of the tests pass successfully. Clearly, I'm at the point where it's possible to compile and run GMP programs. But, when I try to compile the following program:

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <gmp.h>

char *progname;

void print_usage_and_exit ()
{
    fprintf (stderr, "usage: %s -q nnn\n", progname);
    fprintf (stderr, "usage: %s nnn ...\n", progname);
    exit (-1);
}

int main (int argc, char **argv)
{
    mpz_t n;
    int i;

    progname = argv[0];

    if (argc < 2)
        print_usage_and_exit ();

    mpz_init (n);

    if (argc == 3 && strcmp (argv[1], "-q") == 0)
    {
        if (mpz_set_str (n, argv[2], 0) != 0)
            print_usage_and_exit ();
        exit (mpz_probab_prime_p (n, 25) == 0);
    }

    for (i = 1; i < argc; i++)
    {
        int result;
        if (mpz_set_str (n, argv[i], 0) != 0)
            print_usage_and_exit ();
        result = mpz_probab_prime_p (n, 25);
        mpz_out_str (stdout, 10, n);
        if (result == 0)
            puts (" is composite");
        else if (result == 1)
            puts (" is a probable prime");
        else /* result == 2 */
            puts (" is a prime");
    }
    exit (0);
}

with the command:

gcc -m32 -lgmp main.c

I get the following error:

C:\Users\Alex\AppData\Local\Temp\cc2ZHzEt.o:main.c:(.text+0x7f): undefined reference to `_imp____gmpz_init'
C:\Users\Alex\AppData\Local\Temp\cc2ZHzEt.o:main.c:(.text+0xc3): undefined reference to `_imp____gmpz_set_str'
C:\Users\Alex\AppData\Local\Temp\cc2ZHzEt.o:main.c:(.text+0xe2): undefined reference to `_imp____gmpz_probab_prime_p'
C:\Users\Alex\AppData\Local\Temp\cc2ZHzEt.o:main.c:(.text+0x12b): undefined reference to `_imp____gmpz_set_str'
C:\Users\Alex\AppData\Local\Temp\cc2ZHzEt.o:main.c:(.text+0x14a): undefined reference to `_imp____gmpz_probab_prime_p'
C:\Users\Alex\AppData\Local\Temp\cc2ZHzEt.o:main.c:(.text+0x170): undefined reference to `_imp____gmpz_out_str'
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: C:\Users\Alex\AppData\Local\Temp\cc2ZHzEt.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

Can anyone tell what I'm doing wrong? I've done my Googling, and after a few too many hours, any help you can offer would be appreciated. Thanks!

解决方案

The -l options are used to add libraries to your program. Note that order is important! You should always list libraries after all your objects.

Try gcc -m32 main.c -lgmp

这篇关于GMP使用MinGW在Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆