变量声明 - 链接错误 2005 Visual Studio 2008 C++
variable declaration - linking error2005 visual studio 2008 c++
我在yacc.y中有struct errorStruct和一个queue errQueue定义,然后将其移动到单独的.h文件
但它给了我链接错误,该定义在 yacc.obj 和 node.obj 中都可以找到!
尝试创建新的解决方案,但仍然给出相同的错误
Error 9 error LNK2005: "class std::queue<struct errorStruct,class std::deque<struct
errorStruct,class std::allocator<struct errorStruct> > > errQueue" (?errQueue@@3V?$queue@UerrorStruct@@V?
$deque@UerrorStruct@@V?$allocator@UerrorStruct@@@std@@@std@@@std@@A) already defined in Node.obj yacc.obj
更新
第一:
Node.h//for node class
yacc.y//rules + errorStruct + queue errQueue + class ErrList : 包括 "Node.h" &
然后:
Node.h//for node class + errorStruct + queue errQueue + class ErrList : 包括<队列>
yacc.y//规则:包括 "Node.h" 队列>
更新
在节点中
struct errorStruct{
int errLineNum;
int errColNum ;
char * errMessage;
};
class ErrList{
public:
void pushError(int line,int col,char * message);
void popError();
void printErrors();
int getSize();
private :
queue <errorStruct> errQueue;
};
externErrList * se = new ErrList ();
Node.h 的其余部分与此类
无关在 yacc.y 中仅使用se->pushError(...);
并且没有声明类 ErrList 或 errQueue
我相信你应该将代码组织为:
yacc.h //-----> should have declaration of errQueue & errorStruct
yacc.cc //-----> should include yacc.h,
//It can create variables of type errQueue & errorStruct
node.cc //-----> should include yacc.h
//It can create variables of type errQueue & errorStruct
请注意,声明应该只存在于yacc.h
中,并且应该包含在需要创建上述类型实例的所有 cc 文件中,如果除了 header(yacc.h) 之外,在任何 cc 文件中声明了结构,那么你最终会得到你提到的重定义错误。
opss!我忘了发布答案..不好意思。。
在@Peter K.的参考的帮助下得到了它:
转到 VS:项目 -> 属性页 ->配置属性 -> 链接器 ->命令行
并在其他选项框中添加/FORCE:MULTIPLE
相关文章:
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 试图在visual studio上用C++创建一个桌面应用程序
- 如何在MS Visual Studio 2019中运行QT UI
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- Visual Studio Code - C++ Debugger 無法啟動
- Visual Studio 2019:插入多个C++风格的单行注释
- Visual Studio Code "undefined reference to `WinMain@16'"
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- Visual Studio中的函数声明和函数定义问题
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- Visual Studio mkl_link_tool.exe链接错误
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 不同的Visual Studio版本中缺少.dll
- 用Visual Studio在C++中嵌入Julia
- Visual Studio 2017循环自动向量化问题
- 有没有办法在远程设备上打开和编辑visual Studio 2017解决方案
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- Visual Studio在尝试读取resource.txt文件时崩溃
- Visual Studio 2017 不允许我创建 C++ 专用模板