我有来自示例的 5 个文件 - Dec.h、Dec.cpp、decInterface.h、decInterface.cpp 和 temp.c
如何在 c 中使用 c++ 对象? 和 为面向对象的 C++ 代码开发 C 包装 API, 主要在一个名为 temp.c 的文件中,该文件在接口文件的帮助下调用在 Dec.cpp 中实现的 cpp 代码。
它们都驻留在 vs2008 的一个项目中,我已将 compile as 选项设置为默认值,而不是 compile as c 或 compile as c++
我收到以下链接错误
1>Compiling...
1>decInterface.cpp
1>Generating Code...
1>Compiling...
1>temp.c
1>Generating Code...
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Linking...
1>decInterface.obj : error LNK2005: "public: __thiscall Node::Node(class std::vector<float,class std::allocator<float> >)" (??0Node@@QAE@V?$vector@MV?$allocator@M@std@@@std@@@Z) already defined in Dec.obj
1>decInterface.obj : error LNK2005: "public: __thiscall Node::Node(float,float)" (??0Node@@QAE@MM@Z) already defined in Dec.obj
1>decInterface.obj : error LNK2005: "public: __thiscall Node::Node(class std::vector<float,class std::allocator<float> >,class std::vector<bool,class std::allocator<bool> >)" (??0Node@@QAE@V?$vector@MV?$allocator@M@std@@@std@@V?$vector@_NV?$allocator@_N@std@@@2@@Z) already defined in Dec.obj
1>decInterface.obj : error LNK2005: "public: __thiscall reprVectorsTree::reprVectorsTree(class std::vector<class Node *,class std::allocator<class Node *> >,int)" (??0reprVectorsTree@@QAE@V?$vector@PAVNode@@V?$allocator@PAVNode@@@std@@@std@@H@Z) already defined in Dec.obj
1>decInterface.obj : error LNK2005: "public: __thiscall reprVectorsT
ree::reprVectorsTree(float * *,int,int)" (??0reprVectorsTree@@QAE@PAPAMHH@Z) already defined in Dec.obj
1>decInterface.obj : error LNK2005: "private: class std::vector<bool,class std::allocator<bool> > __thiscall reprVectorsTree::binaryForm(int,int)" (?binaryForm@reprVectorsTree@@AAE?AV?$vector@_NV?$allocator@_N@std@@@std@@HH@Z) already defined in Dec.obj
1>decInterface.obj : error LNK2005: "public: class std::vector<float,class std::allocator<float> > __thiscall reprVectorsTree::decode(class std::vector<bool,class std::allocator<bool> >)" (?decode@reprVectorsTree@@QAE?AV?$vector@MV?$allocator@M@std@@@std@@V?$vector@_NV?$allocator@_N@std@@@3@@Z) already defined in Dec.obj
1>decInterface.obj : error LNK2005: "public: float * __thiscall reprVectorsTree::decode(int *,int)" (?decode@reprVe
ctorsTree@@QAEPAMPAHH@Z) already defined in Dec.obj
我应该使用什么样的 Visual Studio 项目设置?我感觉问题出在这里?要链接哪些文件?如何链接?或者默认项目设置应该有效?