编译Codeblocks中的错误未定义引用`__gmpz_mul_ui'

时间:2016-03-11 05:51:42

标签: compiler-errors codeblocks gmp

所以我试图在Codeblocks中编译这段代码:

#include <iostream>
#include <gmpxx.h>

using namespace std;

void
myfunction (mpz_t result, mpz_t param, unsigned long n)
{
  unsigned long  i;

  mpz_mul_ui (result, param, n);
  for (i = 1; i < n; i++)
    mpz_add_ui (result, result, i*7);
}

int
main (void)
{
  mpz_t  r, n;
  mpz_init (r);
  mpz_init_set_str (n, "123456", 0);

  myfunction (r, n, 20L);
  mpz_out_str (stdout, 10, r); printf ("\n");

  return 0;
}

我在编译时遇到此错误

    -------------- Build: Debug in orcs (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -L..\..\Lzip\gmp-6.1.0 -L..\..\Lzip\gmp-6.1.0 -o bin\Debug\orcs.exe obj\Debug\main.o   ..\..\Lzip\mybuilddir\.libs\libgmpxx.a
obj\Debug\main.o: In function `Z10myfunctionP12__mpz_structS0_m':
C:/Users/Joe.Joe/Documents/FMC/orcs/main.cpp:11: undefined reference to `__gmpz_mul_ui'
C:/Users/Joe.Joe/Documents/FMC/orcs/main.cpp:13: undefined reference to `__gmpz_add_ui'
obj\Debug\main.o: In function `main':
C:/Users/Joe.Joe/Documents/FMC/orcs/main.cpp:20: undefined reference to `__gmpz_init'
C:/Users/Joe.Joe/Documents/FMC/orcs/main.cpp:21: undefined reference to `__gmpz_init_set_str'
C:/Users/Joe.Joe/Documents/FMC/orcs/main.cpp:24: undefined reference to `__gmpz_out_str'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
5 error(s), 0 warning(s) (0 minute(s), 0 second(s))

现在我已经在google上调查了这个问题,但我发现这些解决方案似乎没有用。

目前正在Project&gt;构建选项&gt;搜索目录&gt;链接器,我有gmp-6.1.0的位置

我已尝试将gmp放入项目&gt;构建选项&gt;链接器设置&gt;其他链接器选项,但这不起作用,而是给我这个:

-------------- Build: Debug in orcs (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -L..\..\Lzip\gmp-6.1.0 -L..\..\Lzip\gmp-6.1.0 -o bin\Debug\orcs.exe obj\Debug\main.o  gmp  ..\..\Lzip\mybuilddir\.libs\libgmpxx.a
mingw32-g++.exe: error: gmp: No such file or directory
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

我不确定问题出在哪里,因为我非常确定所有内容都安装在默认位置。希望这足以帮助我解决问题:)

0 个答案:

没有答案