我在Visual Studio中的一个解决方案中有两个项目。 其中一个项目(应用程序)依赖于另一个(库)。 该库有一个方法:
int foo(_TCHAR*);它在头文件中正确定义并实现。 在应用程序中,我调用这样的方法:
int bar(_TCHAR* str) { return foo(str); }我得到的错误是
错误LNK2001:无法解析的外部符号“public:int __cdecl foo(char *)”
方法签名完全相同,正在使用相同类型的变量。
I have two projects in one solution in 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 *)"
The method signature is exactly the same and the same type of variable is being used.
最满意答案
链接器无法匹配方法的原因是项目General Properties页面中的Character Set选项不匹配。
该库项目将此选项设置为Use Unicode Character Set并将该应用程序Use Unicode Character Set为Use Multi-Byte Character Set 。
在两个项目中统一字符集解决了这个错误。
The reason behind the linker not being able to match the methods is the mismatched Character Set option in projects General Properties page.
The library project had this option set to Use Unicode Character Set and the application to Use Multi-Byte Character Set.
Unifying the Character Set in both projects fixed this error.
更多推荐
发布评论