LNK2005 error when linking multiple projects that use boost - c++

I have a project that consists from one main project, 3 projects that use boost and few other projects that links to static libraries. These 3 projects use boost. But I can't build my main project. I've got a lot of error LNK2005: .... already defined in ...
errors. As I understood, boost automaticaly links libraries to both of this projects. I tried to use BOOST_ALL_NO_LIB, but it didn't work. After adding this macro I've got unresolved symbols errors, but the redefinition errors still here. How can I solve this problem?
UPD1: there about 400+ errors. Here are first of them:
1>Project_with_boost_1.lib(VS_Project_with_boost_1.obj) : error LNK2005: "unsigned long __cdecl boost::asio::detail::win_tss_ptr_create(void)" (?win_tss_ptr_create#detail#asio#boost##YAKXZ) already defined in Project_with_boost_2.lib(asio.obj)
1>Project_with_boost_1.lib(VS_Project_with_boost_1.obj) : error LNK2005: "void __cdecl boost::asio::detail::do_throw_error(class boost::system::error_code const &,char const *)" (?do_throw_error#detail#asio#boost##YAXABVerror_code#system#3#PBD#Z) already defined in Project_with_boost_2.lib(asio.obj)
1>Project_with_boost_1.lib(VS_Project_with_boost_1.obj) : error LNK2005: "class boost::system::error_category const & __cdecl boost::asio::error::get_misc_category(void)" (?get_misc_category#error#asio#boost##YAABVerror_category#system#3#XZ) already defined in Project_with_boost_2.lib(asio.obj)
1>Project_with_boost_1.lib(VS_Project_with_boost_1.obj) : error LNK2005: "protected: static void __cdecl boost::asio::detail::winsock_init_base::startup(struct boost::asio::detail::winsock_init_base::data &,unsigned char,unsigned char)" (?startup#winsock_init_base#detail#asio#boost##KAXAAUdata#1234#EE#Z) already defined in Project_with_boost_2.lib(asio.obj)
1>Project_with_boost_1.lib(VS_Project_with_boost_1.obj) : error LNK2005: "protected: static void __cdecl boost::asio::detail::winsock_init_base::cleanup(struct boost::asio::detail::winsock_init_base::data &)" (?cleanup#winsock_init_base#detail#asio#boost##KAXAAUdata#1234##Z) already defined in Project_with_boost_2.lib(asio.obj)
1>Project_with_boost_1.lib(VS_Project_with_boost_1.obj) : error LNK2005: "protected: static void __cdecl boost::asio::detail::winsock_init_base::throw_on_error(struct boost::asio::detail::winsock_init_base::data &)" (?throw_on_error#winsock_init_base#detail#asio#boost##KAXAAUdata#1234##Z) already defined in Project_with_boost_2.lib(asio.obj)
1>Project_with_boost_1.lib(VS_Project_with_boost_1.obj) : error LNK2005: "public: void __thiscall boost::asio::detail::win_iocp_io_service::post_deferred_completions(class boost::asio::detail::op_queue<class boost::asio::detail::win_iocp_operation> &)" (?post_deferred_completions#win_iocp_io_service#detail#asio#boost##QAEXAAV?$op_queue#Vwin_iocp_operation#detail#asio#boost###234##Z) already defined in Project_with_boost_2.lib(asio.obj)
1>Project_with_boost_1.lib(VS_Project_with_boost_1.obj) : error LNK2005: "struct boost::asio::detail::signal_state * __cdecl boost::asio::detail::get_signal_state(void)" (?get_signal_state#detail#asio#boost##YAPAUsignal_state#123#XZ) already defined in Project_with_boost_2.lib(asio.obj)
1>Project_with_boost_1.lib(VS_Project_with_boost_1.obj) : error LNK2005: _boost_asio_signal_handler already defined in Project_with_boost_2.lib(asio.obj)
1>Project_with_boost_1.lib(VS_Project_with_boost_1.obj) : error LNK2005: "public: static void __cdecl boost::asio::detail::signal_set_service::deliver_signal(int)" (?deliver_signal#signal_set_service#detail#asio#boost##SAXH#Z) already defined in Project_with_boost_2.lib(asio.obj)
1>Project_with_boost_1.lib(Some_file.obj) : error LNK2005: "unsigned long __cdecl boost::asio::detail::win_tss_ptr_create(void)" (?win_tss_ptr_create#detail#asio#boost##YAKXZ) already defined in Project_with_boost_2.lib(asio.obj)
1>Project_with_boost_1.lib(Some_file.obj) : error LNK2005: "void __cdecl boost::asio::detail::do_throw_error(class boost::system::error_code const &,char const *)" (?do_throw_error#detail#asio#boost##YAXABVerror_code#system#3#PBD#Z) already defined in Project_with_boost_2.lib(asio.obj)
1>Project_with_boost_1.lib(Some_file.obj) : error LNK2005: "class boost::system::error_category const & __cdecl boost::asio::error::get_misc_category(void)" (?get_misc_category#error#asio#boost##YAABVerror_category#system#3#XZ) already defined in Project_with_boost_2.lib(asio.obj)
1>Project_with_boost_1.lib(Some_file.obj) : error LNK2005: "protected: static void __cdecl boost::asio::detail::winsock_init_base::startup(struct boost::asio::detail::winsock_init_base::data &,unsigned char,unsigned char)" (?startup#winsock_init_base#detail#asio#boost##KAXAAUdata#1234#EE#Z) already defined in Project_with_boost_2.lib(asio.obj)
UPD2: I also tried to use macros kind of BOOST_SYSTEM_NO_LIB, BOOST_ASIO_NO_LIB. Result is the same as by using BOOST_ALL_NO_LIB
UPD3: I can set linker option in my main project "Force File Output" to "Multiply Defined Symbols Only /FORCE:MULTIPLE" and project compiles successfully, but during execution it crashes, so I can't use this option.

Your issues have nothing to do with auto linking. The issue is the fact that you've imported boost::asio, a header only library that has some global state, into two separate binaries and linked them together (probably one or more dlls and an exe).
By doing this, you're creating more than one definition of these objects/functions, hence the LNK2005 errors. A bit on that in this post. You need to follow what the manual says about this situation, and build properly. From the docs:
Optional separate compilation
By default, Boost.Asio is a header-only library. However, some
developers may prefer to build Boost.Asio using separately compiled
source code. To do this, add #include <boost/asio/impl/src.hpp> to one
(and only one) source file in a program, then build the program with
BOOST_ASIO_SEPARATE_COMPILATION defined in the project/compiler
settings. Alternatively, BOOST_ASIO_DYN_LINK may be defined to build a
separately-compiled Boost.Asio as part of a shared library.
Emphasis mine. Make sure you define BOOST_ASIO_SEPARATE_COMPILATION is all associated projects that include boost::asio. About the /FORCE:MULTIPLE option, pretend this flag doesn't exist. It's evil, as you can see. It's throwing errors in the garbage that were there to tell you that something is seriously wrong.

Related

Unresolved external symbol ATL::IAtlMemMgr after upgrading to Visual Studio 2019

I am currently upgrading our source code from VS2012 to VS2019. One project which uses MFC does not link successfully:
fatal error LNK1120: 4 unresolved externals
error LNK2001: unresolved external symbol "public: void * __cdecl ATL::IAtlMemMgr::Allocate(unsigned __int64)" referenced in function "public: virtual struct ATL::CStringData * __cdecl ATL::CAtlStringMgr::Allocate(int,int)"
error LNK2001: unresolved external symbol "public: void __cdecl ATL::IAtlMemMgr::Free(void *)" referenced in function "public: virtual void __cdecl ATL::CAtlStringMgr::Free(struct ATL::CStringData *)"
error LNK2001: unresolved external symbol "public: void * __cdecl ATL::IAtlMemMgr::Reallocate(void *,unsigned __int64)" referenced in function "public: virtual struct ATL::CStringData * __cdecl ATL::CAtlStringMgr::Reallocate(struct ATL::CStringData *,int,int)"
error LNK2001: unresolved external symbol "public: virtual struct ATL::CStringData * __cdecl ATL::IAtlStringMgr::Reallocate(struct ATL::CStringData *,int,int)"
We are building with Multi-Byte Character Set (MBCS). My first thought was, that we are missing the the mbcs libraries. But as mentioned here, the libraries are installed by default, "when you select MFC and ATL support".
I added atlbase.h in the code and added atls.lib manually as additional dependency, but that did not solve the problem.
How can I figure out which library is missing?
Edit 1:
Let's take a look into atlmem.h:
__interface __declspec(uuid("654F7EF5-CFDF-4df9-A450-6C6A13C622C0")) IAtlMemMgr{
public:
_Ret_maybenull_ _Post_writable_byte_size_(nBytes) void* Allocate(_In_ size_t nBytes) throw();
As far as I see, this is one of the symbols which is not found. As can be red about the __interface keyword, it implicitly makes the functions pure virtual. These kind of linker errors might be caused by non pure virtual function declarations.
Might there be a bug which makes the functions in the __interface not pure virtual?
After excluding nearly all source files and commenting out a lot of functionality, I could see that the linker errors are correlated to <afxwin.h>. Moving <afxwin.h> to the top of each source files removed the linker errors.
However, I am interested to know why compiling with VS2012 gives another behavior compared to VS2019.

Link errors when trying to compile against an old STD library and windows SDK

I have an old project that is compiled in VS2005 (Sadly). It has to remain in VS2005 so it can link properly to another process which has the VS2005 CRT,MFC, etc.
Now I need to compile this project in VS2015, using the old VS2005 toolset.
I've changed the project's VC++ directories to the old folders for all the STD and Windows SDK headers/libs (Include directories, Reference Directories, Library Directories, Source Directories).
This trick used to work fine while working with VS2010, but on VS2015 I'm getting some weird link errors:
1>Project1.obj : error LNK2019: unresolved external symbol "void __stdcall `eh vector destructor iterator'(void *,unsigned int,unsigned int,void (__thiscall*)(void *))" (??_M#YGXPAXIIP6EX0#Z#Z) referenced in function "public: virtual void * __thiscall PluginInterface::`vector deleting destructor'(unsigned int)" (??_EPluginInterface##UAEPAXI#Z)
1> 1>
1>StdAfx.obj : error LNK2001: unresolved external symbol "void __stdcall `eh vector destructor iterator'(void *,unsigned int,unsigned int,void (__thiscall*)(void *))" (??_M#YGXPAXIIP6EX0#Z#Z)
1> 1>
1>Project1.obj : error LNK2019: unresolved external symbol "void __cdecl operator delete(void *,unsigned int)" (??3#YAXPAXI#Z) referenced in function __unwindfunclet$?getInstance#Project1##SAPAV1#XZ$0
1> 1>
1>Project1.obj : error LNK2019: unresolved external symbol "void __cdecl operator delete[](void *,unsigned int)" (??_V#YAXPAXI#Z) referenced in function "public: virtual void * __thiscall PluginInterface::`vector deleting destructor'(unsigned int)" (??_EPluginInterface##UAEPAXI#Z)
Why is it looking for this inner implementation of the deleter ? Should it be getting the implementation from the headers? Why would it work in VS2010 and not VS2015?
How can I fix this properly ?
So, after reading a lot of breaking changes documentations i found a flag that can suppress these new c++14 delete implementations here, under Placement new and delete.
Adding the flag /Zc:sizedDealloc- removes the missing operator delete() implementations.
Project properties -> Configuration Properties -> C/C++ -> Command Line -> /Zc:sizedDealloc-
you can revert to the old behavior by using the compiler option
/Zc:sizedDealloc-. If you use this option, the two-argument delete
functions don’t exist and won't cause a conflict with your placement
delete operator.
For the eh vector destructor iterator error I've opened a separate question, and answered it there.

Link errors using cryptopp on VS2012 static library, console application and clr program

I have the following project structure on VS2012 C++:
cryptopp: As downloaded and build from cryptopp project.
AccessLib: A static library build using cryptopp functions.
TestApp: A Win32 console application that uses AccessLib (and cryptolib indirectly)
UserApp: A Windows interactive application with CLR support (/clr) that uses AccessLib (and cryptolib indirectly)
Well, my first try was to make this solution work to build my console application and my windows application. BTW, cryptopp was build in a way described in manuals and this SO link. All tests from cryptopp project are running fine in the build environment.
Here is how I´ve build my project:
Set AccessLib as being /Mtd or /MT for Debug or Release respectively, linking with cryptolib.lib from cryptodir\Win32\Output\Debug and cryptodir\Win32\Output\Releaserespectively.
Set TestApp as being also /MTd or /MT for Debug or Release respectively, linking to AccessLib.lib generated from step above.
Fine till now, but when building UserAppit does not work as TestApp needs /clr and that´s incompatible with MTdor /MT.
So, here goes my first question: I can´t have a CLR program that links to a static library that has /MTdor /MT.... What should I do to build my /clr program to my static library AccessLib.lib that access cryptopp as a static library also ? Should I need to convert everything to DLL project ?
Well, I even tried to convert to use cryptopp as a DLL, that way:
Set AccessLib as being /MDd or /MD for Debug or Release respectively, linking with cryptolib.lib from cryptodir\Win32\DLL_Output\Debug and cryptodir\Win32\DLL_Output\Releaserespectively.
That step went fine, but when trying to build TestApp as being also /MDd or /MD for Debug or Release respectively, linking to AccessLib.lib generated from step above, I got several errors like:
1>------ Build started: Project: TestApp, Configuration: Debug Win32 ------
1>cryptlib.lib(hrtimer.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in TestApp.obj
1>cryptlib.lib(pch.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in TestApp.obj
1>msvcprtd.lib(MSVCP110D.dll) : error LNK2005: "public: __thiscall std::_Container_base12::_Container_base12(void)" (??0_Container_base12#std##QAE#XZ) already defined in cryptlib.lib(hrtimer.obj)
1>msvcprtd.lib(MSVCP110D.dll) : error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" (??1_Container_base12#std##QAE#XZ) already defined in cryptlib.lib(hrtimer.obj)
1>msvcprtd.lib(MSVCP110D.dll) : error LNK2005: "public: void __thiscall std::_Container_base12::_Orphan_all(void)" (?_Orphan_all#_Container_base12#std##QAEXXZ) already defined in cryptlib.lib(hrtimer.obj)
1>msvcprtd.lib(MSVCP110D.dll) : error LNK2005: "public: __thiscall std::locale::id::id(unsigned int)" (??0id#locale#std##QAE#I#Z) already defined in cryptlib.lib(pch.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: unsigned char * __thiscall CryptoPP::AllocatorWithCleanup<unsigned char,0>::allocate(unsigned int,void const *)" (?allocate#?$AllocatorWithCleanup#E$0A##CryptoPP##QAEPAEIPBX#Z) already defined in accesslib.lib(Encryptor.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: void __thiscall CryptoPP::AllocatorWithCleanup<unsigned char,0>::deallocate(void *,unsigned int)" (?deallocate#?$AllocatorWithCleanup#E$0A##CryptoPP##QAEXPAXI#Z) already defined in accesslib.lib(Encryptor.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: unsigned char * __thiscall CryptoPP::AllocatorWithCleanup<unsigned char,0>::reallocate(unsigned char *,unsigned int,unsigned int,bool)" (?reallocate#?$AllocatorWithCleanup#E$0A##CryptoPP##QAEPAEPAEII_N#Z) already defined in accesslib.lib(Encryptor.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall CryptoPP::AllocatorWithCleanup<unsigned char,0>::AllocatorWithCleanup<unsigned char,0>(void)" (??0?$AllocatorWithCleanup#E$0A##CryptoPP##QAE#XZ) already defined in accesslib.lib(Encryptor.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall CryptoPP::Rijndael::Enc::Enc(void)" (??0Enc#Rijndael#CryptoPP##QAE#XZ) already defined in accesslib.lib(Encryptor.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall CryptoPP::Rijndael::Enc::~Enc(void)" (??1Enc#Rijndael#CryptoPP##UAE#XZ) already defined in accesslib.lib(Encryptor.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall CryptoPP::Rijndael::Enc::Enc(class CryptoPP::Rijndael::Enc const &)" (??0Enc#Rijndael#CryptoPP##QAE#ABV012##Z) already defined in accesslib.lib(Encryptor.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: static char const * __cdecl CryptoPP::CBC_ModeBase::StaticAlgorithmName(void)" (?StaticAlgorithmName#CBC_ModeBase#CryptoPP##SAPBDXZ) already defined in accesslib.lib(Encryptor.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall CryptoPP::CBC_Encryption::CBC_Encryption(void)" (??0CBC_Encryption#CryptoPP##QAE#XZ) already defined in accesslib.lib(Encryptor.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall CryptoPP::CBC_Encryption::~CBC_Encryption(void)" (??1CBC_Encryption#CryptoPP##UAE#XZ) already defined in accesslib.lib(Encryptor.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall CryptoPP::StreamTransformationFilter::~StreamTransformationFilter(void)" (??1StreamTransformationFilter#CryptoPP##UAE#XZ) already defined in accesslib.lib(Encryptor.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall CryptoPP::StringSinkTemplate<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::StringSinkTemplate<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (??0?$StringSinkTemplate#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###CryptoPP##QAE#AAV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) already defined in accesslib.lib(Encryptor.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall CryptoPP::StringSinkTemplate<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::~StringSinkTemplate<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(void)" (??1?$StringSinkTemplate#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###CryptoPP##UAE#XZ) already defined in accesslib.lib(Encryptor.obj)
1>cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall CryptoPP::Exception::Exception(enum CryptoPP::Exception::ErrorType,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Exception#CryptoPP##QAE#W4ErrorType#01#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) already defined in accesslib.lib(Encryptor.obj)
1>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>accesslib.lib(Encryptor.obj) : error LNK2001: unresolved external symbol "class CryptoPP::NameValuePairs const & const CryptoPP::g_nullNameValuePairs" (?g_nullNameValuePairs#CryptoPP##3ABVNameValuePairs#1#B)
1>c:\project\dev\accesslib\Debug\TestApp.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
I did not move to build UserApp with that configuration.
Help is appreciated to make this whole thing work together. I want to avoid usage of DLL´s at all. My original idea is to have everything as static libraries, but I don´t know if I can achieve that on that solution configuration.
Help appreciated.
You can not link a library compiled with MT or MTd to a program complied with MD or MDd. They have different CRT library.
You can rebuild cryptopp with MD or MDd
That step went fine, but when trying to build TestApp as being also /MDd or /MD for Debug or Release respectively, linking to AccessLib.lib generated from step above, I got several errors like...
You are mixing and matching runtimes. You should probably change Crypto++ and make it use dynamic runtime linking the the C/C++ runtime library. See Visual Studio | Dynamic Runtime Linking on the Crypto++ wiki.
I want to avoid usage of DLL´s at all. My original idea is to have everything as static libraries, but I don´t know if I can achieve that on that solution configuration.
Yes, this is preferred. It will work, but you need to build the Crypto++ static library using dynamic runtime linking. The project you want is cryptlib, and its output is found in <crypto++ dir>/Output/{Debug|Release}/{Win32|x64}. See the previous links.
You should also avoid the FIPS DLL. The DLL project is cryptdll, and its output is found in <crypto++ dir>/DLL_Output/.... The DLL is special purpose, and it only provides FIPS algorithms. Its not a general purpose DLL, it lacks most stuff you need, and it causes a lot of pain and misery.
I even go so far as to tell people to completely delete the cryptdll and dlltest projects because they cause so much trouble. Also see FIPS DLL on the Crypto++ wiki.
Link errors using cryptopp on VS2012 static library, console application and clr program
This is noteworthy... Crypto++ does not use the /clr option. You will need to modify the static library project settings and add it.
The static library's project is called cryptlib. You will need to do it for Win32 Debug, Win32 Release, x64 Debug and x64 Release.

Mixing native C++ and C++/CLI

I have a solution which consists of a native C++ DLL and a C++/CLI wrapper. My aim is to create a wrapper in C++/CLI of the native C++ DLL.
Whenever I try to create an instance of a native C++ class within the wrapper, I am met with many linker errors (see below).
2> .NETFramework,Version=v4.0.AssemblyAttributes.cpp
2>NFileOperation.obj : error LNK2028: unresolved token (0A000208) "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z) referenced in function "[T2M] void __clrcall `dynamic initializer for 'public: static float * tagVARIANT::* ATL::CVarTypeInfo<float *>::pmField''(void)" (__t2m#???__E?pmField#?$CVarTypeInfo#PAM#ATL##2QQtagVARIANT##PAMQ3###YMXXZ#?A0x22b777aa##YMXXZ)
2>DeskUpdateManaged.obj : error LNK2028: unresolved token (0A00021C) "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z) referenced in function "public: bool __clrcall DeskUpdateManaged::Conversion::FileExist(class System::String ^)" (?FileExist#Conversion#DeskUpdateManaged##$$FQ$AAM_NP$AAVString#System###Z)
2>DeskUpdateManaged.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z) referenced in function "public: bool __clrcall DeskUpdateManaged::Conversion::FileExist(class System::String ^)" (?FileExist#Conversion#DeskUpdateManaged##$$FQ$AAM_NP$AAVString#System###Z)
2>NFileOperation.obj : error LNK2001: unresolved external symbol "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z)
2>C:\Users\ABGZAMANK\Music\DeskUpdate\Dev\Source\Solution\Debug\DeskUpdateManaged.dll : fatal error LNK1120: 3 unresolved externals
Function call within the C++/CLI to the native C++ DLL:
bool NFileOperation::FileExists(CAtlString sPathName)
{
return CFileOperation::FileExists(sPathName);
}
Is there a more adequate approach to what I am trying to achieve?
Any advice relating to the issue is much appreciated.
It seems that your native C++ code is using ATL/MFC. Assuming you are compiling under VS, go to the C++/CLI project's project properties->Configuration properties->General and select "Use of MFC" and "Use of ATL" to be either static library or shared dll (depending on your project type). This flag will add the necessary include paths, linking paths and libs to your project to make use of ATL/MFC types from within your project. Also, make sure that you are linking your C++/CLI project against your native C++ project to avoid linking errors from your project (easily found in the Linker segment of the project properties in General and Input).

Strange LNK2001 linker error

Yesterday I got this linker error. I have searched on google and msdn without success.
My problem:
I have moved some parts of my cpp project in a extern static library. I added the h file to my main project and added the dependencies to the lib files. Unfortunately I get a lot linker errors.
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NFile::NFind::CFileInfo::Find(unsigned short const *)" (?Find#CFileInfo#NFind#NFile#NWindows##QAE_NPBG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: class NWindows::NCOM::CPropVariant & __thiscall NWindows::NCOM::CPropVariant::operator=(unsigned short const *)" (??4CPropVariant#NCOM#NWindows##QAEAAV012#PBG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CInFileStream::Open(unsigned short const *)" (?Open#CInFileStream##QAE_NPBG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NFile::NIO::COutFile::Create(unsigned short const *,bool)" (?Create#COutFile#NIO#NFile#NWindows##QAE_NPBG_N#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "void __cdecl ConvertUInt32ToString(unsigned int,unsigned short *)" (?ConvertUInt32ToString##YAXIPAG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NDLL::CLibrary::Load(unsigned short const *)" (?Load#CLibrary#NDLL#NWindows##QAE_NPBG#Z)
All this methods a part of my extern lib. I have tries a lot of compiler settings without success.
Further more when I remove the lib dependencie completely from the linker I get 26 LNK2001 error. So the linker finds only "parts" of the lib.
Do I use a wrong compiler / linker option for my projects?
edit:
The problem was the parameter define LPCTSTR of the method CLibrary::Load(LPCTSTR fileName). In my lib I set the option "Treat wchar_t as build-in type (Properties->C/C++->Lanuage-> ... ) to No. And now it works.
There's not enough information in the question so my answer merely serves as a guide.
Take one function, for instance bool NWindows::NFile::NFind::CFileInfo::Find(unsigned short const *) and find definition of it in your code. Is it there? With this exact function signature? Is it in unnamed namespace? Is it declared static in source file?
Also, try full rebuild of everything. You'd be surprised how many times full rebuild makes mysterious problems go away.