简体   繁体   English

两个项目之间的MFC CString链接器错误

[英]MFC CString Linker error between two projects

I have 2 projects in c++ (MFC) One is a library project which im using in the second one (an executable one). 我在c ++(MFC)中有2个项目,一个是我在第二个项目(可执行文件)中使用的库项目。

They work together great, until I call a function from the regular project that takes a CString as argument. 它们可以很好地协同工作,直到我从常规项目中调用以CString作为参数的函数为止。 I get a linker error like this 我收到这样的链接器错误

error LNK2019: unresolved external symbol "public: void __thiscall 
CTextDisplay::SetText1(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,
class ATL::ChTraitsCRT<wchar_t> > >)" (?SetText1@CTextDisplay@@QAEXV?$CStringT@_WV?
$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@@Z) referenced in function 
"public: void __thiscall CManualPane::SetBeadCountFor(int,double)" 
(?SetBeadCountFor@CManualPane@@QAEXHN@Z)    C:\source\IQ-Project\IQ\ManualPane.obj  IQ

The executable project has its character set to UNICODE but the Library has it set to Multy-Byte chatacter set. 可执行项目的字符集设置为UNICODE,而库文件集的字符集设置为Multy-Byte chatacter。 I really can't change them without getting ridiculous amounts of errors. 我真的无法更改它们,而不会收到很多荒谬的错误。

Any suggestions? 有什么建议么?

Edit: The reason we have different settings in these two projects is because the Executable project is basically an external project that my group didn't build or create. 编辑:我们在这两个项目中具有不同设置的原因是,因为可执行项目基本上是我的小组未构建或创建的外部项目。 We just had to bring it in and use it. 我们只需要将其引入并使用它。 The library project is something we've all been working on for a couple years. 图书馆项目是我们大家一直在努力的两年。

When you include the headers of the library project in the executable, there is likely a typedef which is used in the declaration of the function. 当您在可执行文件中包含库项目的标题时,可能在函数的声明中使用了typedef。 Since the executable uses UNICODE, the declaration is now in UNICODE. 由于可执行文件使用UNICODE,因此声明现在在UNICODE中。 However, the library implementation is still in MultiByte and so the definition doesn't match the declaration leading to the linker error. 但是,库实现仍在MultiByte中,因此定义与导致链接器错误的声明不匹配。

Look into how these typedefs are being setup, and you might be able to do some special #define, #undef around the included header. 研究一下这些typedef的设置方式,您也许可以对包含的标头进行一些特殊的#define和#undef。

最后,最好避免在同一解决方案中包含unicode和multybyte项目,因此我将其全部移至unicode并从那里移走

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

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