VS 2005 で C++ プロジェクト ソリューションをコンパイル中にリンク エラーが発生しました。シナリオは次のとおりです。
MySolution
という名前の2つのプロジェクトがあると言う解決策があります
MyTestLib
文字セットUse Multi-Byte Character Set
を使用し、CLR
サポートされていないスタティック ライブラリ タイプのプロジェクトです。
と
MyTestApp
上記の lib を使用し、文字セットUse Unicode Character Set
とCLR
サポートを備えた .exe アプリです。
次のMyTestLib
定義を持つ2つのオーバーロードされた関数があります
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
ようになります
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
、すべてのエラーが解決されます。しかし、他の依存関係があるため、プロジェクトの文字セットを変更できません。
回避策はありますか?