我使用 Microsoft Visual Studio 2008 编译了 C++ 的 NTL 无限精度整数算术库。我按照解释做了 这个网站, ,使用 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() ?

非常感谢帮助!

有帮助吗?

解决方案

mpqs.h 肯定被包含在内,因为输出要求您引用它。

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

另外,您不应该将库文件包含在构建中的某个位置吗?

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

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

至于库,只有编译成功后才能使用该库。所以现在不用担心。进入那里并修复 MSVC 报告的错误!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top