首页 文章

Visual Studio 2013中的C - <Class>未定义

提问于
浏览
0

我是C / VS的新手,可能会在项目的代码/配置中遗漏一些东西 . 在我的解决方案中,我有2个项目:

  • 首先是我从https://bitbucket.org/ben_key/ntl下载的NTL,并编译为静态库NTL.lib .

  • 一个'test'项目,其中:(1)我通过在属性 - > C - >附加包含文件中指定了它们的目录,添加了头文件,属性 - >链接器 - >输入 - >附加依赖项中的(2)我添加了"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 ==========

这真的很简单,我没想到我错过了什么 .

1 回答

  • 3

    从NTL / include / NTL / tools.h:

    #define NTL_NAMESPACE NTL
    #define NTL_OPEN_NNS namespace NTL_NAMESPACE {
    #define NTL_CLOSE_NNS  }
    

    因此,当预处理器遇到 NTL_OPEN_NNS 时,就像包含文件GF2X.h中的情况一样,它将它扩展为 namespace NTL ,这意味着GF2X类被声明为命名空间NTL . 为了使用它,您需要完全限定它为 NTL::GF2X 或使用 using namespace NTL 来讨论哪一个看起来像here . 同样在扩展NTL_CLOSE_NNS后,在GF2X.h结束时有一个结束括号

相关问题