【发布时间】:2014-11-03 11:34:13
【问题描述】:
我对 C++/VS 非常陌生,可能会在我的项目的代码/配置中遗漏一些东西。 在我的解决方案中,我有 2 个项目:
- 首先是我从https://bitbucket.org/ben_key/ntl下载的NTL,编译成静态库NTL.lib。
- 一个“测试”项目,其中:(1) 我通过在 properties->C++->Additional Include Files 中指定头文件的目录来添加头文件,(2) 在 properties->Linker->Input->Additional依赖项我添加了“NTL.lib”(3)将 NTL.lib 文件复制到与“test”项目的主 cpp 文件相同的目录中。
我的 cpp 只包含:
#include <NTL/GF2X.h>
int main() {
GF2X P;
return 1;
}
构建给出了输出:
1>------ Build started: Project: test, Configuration: Release Win32 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppBuild.targets(388,5): warning MSB8028: The intermediate directory (Release\) contains files shared from another project (ntl-test.vcxproj). This can lead to incorrect clean and rebuild behavior.
1> QuickTest.cpp
1>..\tests\QuickTest.cpp(43): warning C4101: 'n' : unreferenced local variable
1>D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(79): warning C4291: 'void *operator new(size_t,_ntl_vector_placement)' : no matching operator delete found; memory will not be freed if initialization throws an exception
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(36) : see declaration of 'operator new'
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(319) : see reference to function template instantiation 'void NTL::BlockConstruct<T>(T *,long)' being compiled
1> with
1> [
1> T=NTL::zz_p
1> ]
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(291) : while compiling class template member function 'void NTL::Vec<NTL::zz_p>::DoSetLength(long)'
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(115) : see reference to function template instantiation 'void NTL::Vec<NTL::zz_p>::DoSetLength(long)' being compiled
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vec_lzz_p.h(14) : see reference to class template instantiation 'NTL::Vec<NTL::zz_p>' being compiled
1> MyTest.cpp
1>MyTest.cpp(4): error C2065: 'GF2X' : undeclared identifier
1>MyTest.cpp(4): error C2146: syntax error : missing ';' before identifier 'P'
1>MyTest.cpp(4): error C2065: 'P' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
这真的是一件简单的事情,我没有弄清楚我错过了什么。
【问题讨论】:
-
该标头以
NTL_OPEN_NNS开头,这是一个可能扩展为namespace NTL{左右的宏。因此你需要使用 NTL::GF2X;除此之外,可能会针对缺少操作员删除的警告提交错误报告。如果编译器诊断正确,可能会导致内存泄漏或更糟。
标签: c++ visual-c++ header-files