在 VS 2005 中编译我的 C++ 项目解决方案时出现链接错误。以下是场景。
我有一个解决方案,可以说MySolution
其中有 2 个名为
MyTestLib
是具有字符集且不支持的静态库Use Multi-Byte Character Set
类型CLR
项目
和
MyTestApp
Use Unicode Character Set
是一个 .exe 应用程序,使用带有字符集和CLR
支持的上述库
其中MyTestLib
有两个具有以下定义的重载函数
int Class1::test1(int a)
{
return a+4;
}
bool Class1::test1(LPCTSTR param)
{
return true;
}
MyTestApp
正在从它的代码中调用它们,例如
Class1 objcl1;
int a = objcl1.test1(12); //Works fine
Class1 objcl2;
string abc = "adsad";
bool t = objcl2.test1(abc.c_str()); //Error
调用test1(LPCTSTR)
版本会出错
Error 1 error C2664: 'int TestLib::Class1::test1(int)' : cannot convert parameter 1 from 'const char *' to 'int'
如果我将语句更改为bool t = objcl2.test1((LPCTSTR)abc.c_str()); //Now linking Error
Then 我得到
Error 2 error LNK2001: unresolved external symbol "public: bool __thiscall TestLib::Class1::test1(wchar_t const *)" (?test1@Class1@TestLib@@$$FQAE_NPB_W@Z) TestProject.obj
但是如果我将项目MyTestApp
字符集更改为,Use Multi-Byte Character Set
那么所有错误都将得到解决。但我无法更改项目字符集,因为还有其他依赖项。
周围有工作吗?