-1

error is:

Error 14 error LNK2005: "void __stdcall _set_com_error_handler(void (__stdcall*)(long,struct IErrorInfo *))" (?_set_com_error_handler@@YGXP6GXJPAUIErrorInfo@@@Z@Z) already defined in comsupp.lib(comsupp.obj) comsuppwd.lib

Did anyone run into this before?

Megidd
  • 7,089
  • 6
  • 65
  • 142
  • The declaration and definition signatures of a function must match. In your case, the definition doesn't change, so the linker can't find the function by its declaration signature. – Alexei Averchenko Apr 21 '15 at 19:50
  • @AlexeiAverchenko I modified both declaration and definition. I feel like the error has to do with my implementation inside my definitions. – Megidd Apr 21 '15 at 19:56
  • 1
    Sorry, I didn't look at the error text at first. Looks like some function is declared in multiple object files. It can happen if a function body is defined in a header file, for example. – Alexei Averchenko Apr 21 '15 at 20:02
  • @AlexeiAverchenko You're right. Error is about `comsupp.lib` and `comsuppwd.lib` I'm not sure how these libraries are involved. – Megidd Apr 21 '15 at 20:11
  • @AlexeiAverchenko Problem is resolved now. It was due to a header file: `#include ` – Megidd Apr 21 '15 at 20:28

2 Answers2

1

There is a bug in the Visual Studio 2010 header <msclr/marshal.h>. There is written

#pragma comment(lib, "comsupp.lib")

but compared to <comdef.h> there must be written

#ifdef _NATIVE_WCHAR_T_DEFINED
# ifdef _DEBUG
# pragma comment(lib, "comsuppwd.lib")
# else
# pragma comment(lib, "comsuppw.lib")
# endif
#else
# ifdef _DEBUG
# pragma comment(lib, "comsuppd.lib")
# else
# pragma comment(lib, "comsupp.lib")
# endif
#endif

See also the Lib-section in https://learn.microsoft.com/de-de/cpp/cpp/set-com-error-handler?view=vs-2019

So you have 2 Options

  1. BAD: Edit the msclr/marshal.h in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\msclr\marshal.h. But then all collegues must change their file too.
  2. Change the ProjectSetting Linker -> Input -> Ignore Specific Default Libraries and add commsupp.lib. !!!But attention if you have set the compiler option /Zc: wchar_t- (see C/C++ -> Language -> Treat WChar_t as Built in Type) AND compiling for Release then it must not be ignored!!! So each project configuration may/must be changed differently.
David Buck
  • 3,752
  • 35
  • 31
  • 35
Georg
  • 11
  • 2
0

Error is resolved now. The cause of error was a header file: #include <msclr\marshal_cppstd.h> and conversion from System::String^ to std::string(I found a similar issue here):

//commented out following 3 lines and problem solved:
//looks like following type conversion has problems:
#include <msclr\marshal_cppstd.h>
msclr::interop::marshal_context marshal_context_1;
string_TempDir_XMLfiles=marshal_context_1.marshal_as<std::string>(String_Ptr_Destin_Dir_XMLfiles);
Community
  • 1
  • 1
Megidd
  • 7,089
  • 6
  • 65
  • 142