[英]unresolved external symbol in c++
I have defined a global variable in a c++ file. 我在c ++文件中定义了一个全局变量。 eg:
bool _variable =1;
例如:
bool _variable =1;
Now i use this variable in other c++ file using : extern bool _variable
. 现在,我在其他c ++文件中使用以下变量:
extern bool _variable
。
But i am getting the error error LNK2001: unresolved external symbol "bool _variable" (?_variable@@3_NA)
. 但是我收到错误
error LNK2001: unresolved external symbol "bool _variable" (?_variable@@3_NA)
。
How can i resolve this error?? 我该如何解决此错误?
It means the linker cannot find the definition of such variable. 这意味着链接器找不到此类变量的定义。
Are you sure you wrote it in the same way anywhere? 您确定在任何地方都以相同的方式编写它吗?
Are you sure the c++ file containing the definition gets compiled and linked with the others when you're getting such error? 您确定在遇到此类错误时包含定义的c ++文件是否已编译并与其他文件链接吗?
Are you sure the namespace where such variable is defined is the same? 您确定定义此类变量的名称空间是否相同?
也许您忘记了将具有定义变量的文件包含到项目中(假设您使用的是VS)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.