简体   繁体   中英

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).

They work together great, until I call a function from the regular project that takes a CString as argument. 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. 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. Since the executable uses UNICODE, the declaration is now in UNICODE. However, the library implementation is still in MultiByte and so the definition doesn't match the declaration leading to the linker error.

Look into how these typedefs are being setup, and you might be able to do some special #define, #undef around the included header.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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