简体   繁体   English

即使函数存在char *,仍然存在未解析的外部符号错误

[英]unresolved external symbol error even though the function exists char*

I have two projects in one solution in Visual Studio. 我在Visual Studio中的一个解决方案中有两个项目。 One of the projects (application) depends on another (library). 其中一个项目(应用程序)依赖于另一个(库)。 The library has a method: 该库有一个方法:

int foo(_TCHAR*);

It is properly defined in header and implemented. 它在标头中正确定义并实现。 In the application I call the method like this: 在应用程序中,我调用这样的方法:

int bar(_TCHAR* str) {
  return foo(str);
}

The error I am getting is 我得到的错误是

error LNK2001: unresolved external symbol "public: int __cdecl foo(char *)" 错误LNK2001:未解析的外部符号“public:int __cdecl foo(char *)”

The method signature is exactly the same and the same type of variable is being used. 方法签名完全相同,并且使用相同类型的变量。

The reason behind the linker not being able to match the methods is the mismatched Character Set option in projects General Properties page. 链接器无法匹配方法的原因是项目“ General Properties页面中的“ Character Set选项不匹配。

The library project had this option set to Use Unicode Character Set and the application to Use Multi-Byte Character Set . 库项目将此选项设置为Use Unicode Character Set和应用程序以Use Multi-Byte Character Set

Unifying the Character Set in both projects fixed this error. 统一两个项目中的字符集修复了此错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM