Netbeans(Windows 64位)中带有C++的GMP错误
Error with GMP with C++ in Netbeans (Windows 64-Bit)
我正在为学校做一个项目,在这个项目中,我正在进行涉及素数的各种不同计算。这些数字往往很大,因此我去寻找一个任意精度的库。我决定去GMP,因为我之前在Game Maker中使用过它(一个相对未知的程序),因为有人为它制作了一个dll。
现在,我已经按照安装手册进行了GMP的编写。我很难做到这一点,因为我完全不熟悉UNIX和cygwin。现在,我已经尝试在Netbeans中包含gmpxx.h作为测试程序,但事情出了问题。我的代码如下:
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <gmpxx.h>
#include <stdarg.h>
using namespace std;
int main()
{
mpz_t a;
mpz_init(a);
//cout << mpz_probab_prime_p(a,20);
mpz_clear(a);
}
对于mpz_init和mpz_clear,我都得到了相同的错误:
根据未定义的符号'__gmpz_[init/clear]'截断重新定位以适应:R_X86_64_PC32
我只是猜测,但问题可能是以下任何一种:
- 编译错误
- 错误代码
- 包含/链接不正确
它很可能是后者,尽管我已经尝试过为头文件等添加目录。我该如何修复此错误?
提前感谢
编辑:既然这是我的第一篇帖子,你能指出我需要澄清什么才能回答这个问题吗?
第2版:这是Netbeans:中的编译日志
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/firsttestgmp.exe
make[2]: Entering directory '/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP'
mkdir -p dist/Debug/Cygwin_4.x-Windows
g++ -Lpath/to/gmp/lib -lgmpxx -lgmp -o dist/Debug/Cygwin_4.x-Windows/firsttestgmp build/Debug/Cygwin_4.x-Windows/main.o
build/Debug/Cygwin_4.x-Windows/main.o: In function `main':
/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP/main.cpp:22: undefined reference to `__gmpz_init'
/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP/main.cpp:22:(.text+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__gmpz_init'
/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP/main.cpp:24: undefined reference to `__gmpz_clear'
/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP/main.cpp:24:(.text+0x21): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__gmpz_clear'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/Cygwin_4.x-Windows/firsttestgmp.exe' failed
make[2]: *** [dist/Debug/Cygwin_4.x-Windows/firsttestgmp.exe] Error 1
make[2]: Leaving directory '/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
第3版:正如@rubenwd所指出的,真正的错误是:
build/Debug/Cygwin_4.x-Windows/main.o: In function `main':
/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP/main.cpp:22: undefined reference to `__gmpz_init'
重要的是,链接库位于包含对它们的引用的对象文件之后。所以你的编译命令需要是:
g++ -o dist/Debug/Cygwin_4.x-Windows/firsttestgmp build/Debug/Cygwin_4.x-Windows/main.o -lgmpxx -lgmp
如果您在非标准位置安装了GMP(事实并非如此),则需要使用-L
选项添加库目录的路径。
谢谢大家!我通过以下操作解决了问题:属性>构建>链接器>库>添加库然后添加gmp.a和gmpxx.a,它们是我在编译的gmp目录中找到的。
相关文章:
- 使用 GMP 的 while 循环出现问题
- 有没有一个 c++ gmp 库函数与 python gmpy2 库 divm(..) 函数相同?
- 使用 MinGW 在 Windows 上安装 GMP 时出错
- 为什么gmp会在这里与"invalid next size"重新定位一起崩溃?
- MSYS2 MinGW64 在 Windows 上构建 GMP/MPFR 作为静态库,并将它们链接到使用 CL 编译的
- 尝试运行 gmp 时未找到 MPIR.dll
- GMP-将64位整数存储在mpz_t/mpz_class中,并返回64位整数
- 使用Rcpp返回GMP类
- C++ - 带有 % 运算符的 GMP 库错误
- 如何导入使用自制软件安装的 GMP?
- 为什么提升日志中断会提升 GMP 多精度?
- 使用 GMP/ARB 矩阵减少 OpenMP
- 使用GMP在C 中编译代码
- 如何使用 GMP 创建浮点数组?
- gmp 的 libgmp.so 有哪些依赖关系?我不断收到未定义的引用
- 如何使用整数初始化 GMP mpz_t
- 如何使用 std::cout 和 mini-gmp mpz-t.
- 使用GMP安装NTL
- GMP 中变量的初始化
- 如何使用Visual Studio为windows编译GMP