【问题标题】:Compiling and using NTL c++ library for Windows为 Windows 编译和使用 NTL c++ 库
【发布时间】:2010-04-12 09:59:19
【问题描述】:

我已经使用 Microsoft Visual Studio 2008 为 c++ 编译了 NTL 无限精度整数算术库。我按照 this site 上的说明进行了操作,使用 Visual Studio 界面,而不是从命令提示符。其实我宁愿在命令提示符下做,但我不知道怎么做。

无论如何,我已经编译了库,现在我想在命令提示符下使用该库编译一个程序。我正在尝试编译的程序已经在 linux 系统上进行了测试,我使用以下代码编译它

c++ -I/appl/htopopt/Linux_x86_64/NTL-5.4.2/include mpqs.cpp main.cpp -o main -L/appl/htopopt/Linux_x86_64/NTL-5.4.2/lib -lntl -L/appl/htopopt/Linux_x86_64/gmp-4.2.1/lib -lgmp -lm

没关系 gmp 的东西,我没有在 Windows 上安装它。这纯粹是一个可选的东西,可以让 NTL 运行得更快。无论如何,这在 linux 上运行良好。现在在 Windows 上我写了以下内容

cl /EHsc /I D:\Downloads\WinNTL-5_5_2\include mpqs.cpp main.cpp /link /LIBPATH:"D:\Documents\Visual Studio 2008\Projects\ntl\Debug"

但这会导致以下错误:

mpqs.cpp
mpqs.cpp(38) : error C2039: 'find_smooth_vals' : is not a member of 'QS'
        d:\desktop\qs\mpqs.h(12) : see declaration of 'QS'
mpqs.cpp(41) : error C2065: 'M' : undeclared identifier
mpqs.cpp(41) : error C2065: 'n' : undeclared identifier
mpqs.cpp(42) : error C2065: 'sieve_table' : undeclared identifier
mpqs.cpp(42) : error C2228: left of '.size' must have class/struct/union
        type is ''unknown-type''
mpqs.cpp(43) : error C2065: 'sieve_table' : undeclared identifier
mpqs.cpp(44) : error C2065: 'qx_table' : undeclared identifier
mpqs.cpp(44) : error C3861: 'test_smoothness': identifier not found
mpqs.cpp(45) : error C2065: 'smooth_indices' : undeclared identifier
mpqs.cpp(45) : error C2228: left of '.push_back' must have class/struct/union
        type is ''unknown-type''
main.cpp
Generating Code...

好像,我的mpqs.h文件没有包含在编译过程中?另外我不明白为什么它抱怨向量类型的 .push_back() ?

非常感谢您的帮助!

【问题讨论】:

  • NTL 已严重过时,请改用MPIR

标签: c++ visual-c++ ntl


【解决方案1】:

mpqs.h 肯定包含在内,因为输出要求您参考它。

看到 MPQS.h 似乎没有包含在 NTL 库中……是你写的吗?如果可以,可以把代码贴出来吗?

另外,您不应该在构建的某处包含库文件吗?

编辑:没有函数 find_smooth_values 那么为什么要让 MSVC 找到它呢?我不确定为什么在 GCC 下编译但它显然丢失了。我猜其他错误是由于这个错误引起的。错误告诉你一些事情。你应该听他们的。

push_back 失败是因为它不知道您尝试 push_back 的类型是什么。这又可能是由于 find_smooth_values 不存在这一事实造成的。尝试将函数原型添加到 QS 类中。这可能会解决您的所有问题。

至于库,在编译成功之前它不会使用该库。所以现在不要担心这个。进入那里并修复 MSVC 报告的错误!

【讨论】:

  • 是的,我编写了 mpqs.h,它与 mpqs.cpp 和 main.cpp(使用 mpqs 类的可运行文件)位于同一目录文件夹中。我尝试在构建命令的末尾添加“ntl.lib”,但它给了我同样的错误。我不确定我是否可以在评论中发布代码,但我将其粘贴在这里:pastebin.com/mLN5K40E
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-29
  • 2011-04-25
  • 2021-07-16
相关资源
最近更新 更多