无法解析的外部符号错误,即使函数存在char *(unresolved external symbol error even though the function exists char*)

编程入门 行业动态 更新时间:2024-10-24 14:26:41
无法解析的外部符号错误,即使函数存在char *(unresolved external symbol error even though the function exists char*)

我在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.

更多推荐

本文发布于:2023-04-27 23:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329084.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   符号   错误   char   unresolved

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!