Fatal error LNK1179: invalid or corrupt file: duplicate COMDAT '_IID_IXMLDOMImplementation'

I get this one error when I link my project,

COMMUNICATION.obj: fatal error LNK1179: invalid or corrupt file: duplicate COMDAT '_IID_IXMLDOMImplementation'

What is the source of the problem?

+12
visual-c ++ visual-studio-2005
Aug 21 '12 at 11:41
source share
7 answers

It's a difficult question.

The problem is that the (s) -generated character is too long and there is ambiguity:

//... void MyVeryLongFunctionNameUnique_0(void); void MyVeryLongFunctionNameUnique_1(void); // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // (example max-symbol-length-seen-by-linker) 

In this case, the linker “sees” these two functions as “the same,” because the part that makes them “unique” is longer than the length of the -max symbol.

This can happen in at least three cases:

  • Your character names are too long to be considered unique for the linker, but perhaps it was good for the compiler (for example, when you expand access to many nested templates)
  • You did a “trick” which is invalid C ++, and it passed the compiler, but now you have an invalid *.obj , and it pinches the linker.
  • You specified duplicate "unnamed" classes / structures, and the linker cannot resolve them.
  • === [UPDATE] === . This is not your mistake, this is an internal problem with the compiler and / or linker (see below for possible possibilities).

Depending on the problem (above), you can "increase" the length of the character (by limiting the length of your character), or correct your code to make it valid (unambiguous) C ++.

This error is (minimally) described by Microsoft at:

NOTE. . This maximum character length can be set using the /H option, see http://msdn.microsoft.com/en-us/library/bc2y4ddf(v=vs.90).aspx

  • RECOMMENDS:. Check if /H on your command line. If so, delete it (do not specify max-symbol-length, by default it will be 2,047 , /H can only reduce this length, not increase it).

However, you probably called it with the /Gy (function level binding) option, which was probably implied through one of /Z7 , /Zi or /Zi : http://msdn.microsoft.com/en-us/ library / 958x11bc (v = vs.90) .aspx

One MSDN thread that talks about this issue:

This thread suggests that you can cause this problem with "invalid-C ++ - code-that-compiles" (you get your *.obj ), but this invalid *.obj delays the linker (this example tries to use main as a function and as a template):

=== [UPDATE] ===

I should have said this before because I suspected, but now I have additional information. Perhaps this is not your fault. It seems that a problem in the compiler and / or linker is causing this error. This is despite the fact that the only common denominator in all of your failed relationships is you.

Recall that the “inscription” applies (it MAY be your mistake). However, in case “it’s not your fault”, the current list is here (I'm sure this list is NOT completed).

  • Your *.ilk file (intermediate link file) has an internal error / corruption. Remove it and rebuild.
  • You have /INCREMENTAL enabled for communication, but for some reason this incremental binding does not work for your project, so you should disable it and rebuild ( Project-Properties=>Configuration Properties=>Linker=>General=>Enable Incremental Linking [install in No ( /INCREMENTAL:NO )]
  • The problem with "Optimization" for "Collapsible COMDAT" in your use. You can "Remove Redundant COMDAT" by going to Project Proerties=>Configuration Properties=>Linker=>Optimization=>Enable COMDAT Folding , set "Delete Redundant COMDAT ( /OPT:ICF )

Here is an interesting thread from a guy who can sometimes refer, and sometimes not, commenting on / from a couple of lines of code. This is not the code that is the problem - it simply cannot bind sequentially, and it seems that the compiler and / or linker have an internal problem in some obscure use case:

Other observations from a non-trivial web search:

  • This problem is not uncommon.
  • it seems to be associated with some form of template<> uses
  • others seem to see this problem with the Release build when it did not have this problem with the Debug build (but it is also common in the Debug build).
  • If the link “failed” on one machine, it can “succeed” on another build machine (not sure why a “clean build” has no effect).
  • if you comment on / from particularly meaningful lines of code and complete the build, and continue to do so until all the code is commented again, your link may succeed (this seems to be repeatable)
  • if you get this error with MSVC2008 and you port your code to MSVC2010, you will still get this error.

=== [PETIN FOR GOOD PEOPLE OF THE WORLD] ===

If you have other comments about this error, list them below (like other answers or comments below this answer). I have a similar problem, and it's not my fault, and none of these work-arounds worked for me (although in some cases they worked for others in their projects).

I add generosity because it drives me crazy.

=== [UPDATE + 2] ===

(sigh) Here are more things to try (which apparently work for others but don't work for me):

  • this guy changed his compilation settings and it worked (from the stream at http://forums.codeguru.com/showthread.php?249603.html ):

    Project->Settings->C++ tab, Debug cathegory: Inline function expansion : change the value from ' None ' to ' Only _inline '.

  • the above thread refers to another thread where it was necessary to reinstall MSVC

  • possibly due to the binding of modules with "subtle differences" in possibly incompatible compilers and / or link switches. Make sure all "libs tabs" are built using the same keys.

Here are some more symptoms / observations for this error / error:

  • List
  • for the above problems still apply
  • the problem seems to be an "initial reading" with MSVC2005 and continues with the same behavior for MSVC2008 and MSVC2010 (the error still occurs after porting the code to newer compilers)
  • rebooting the IDE; rebooting the machine does not seem to work for anyone.
  • one guy said that a clear “clean”, followed by recompilation, worked for him, but many others say that it did not work for them.
  • often associated with "incremental binding" (for example, disable it).

Status: no joy.

=== [UPDATE + 3: SUCCESS LINKS] ===

Super-wacky-does-no-sense fix to successfully establish a connection!

This is the option (above) in which you “play” with a script-with-code-to-compiler and / or-linker. ”NOT GOOD that this may be needed.

The specific error of the single linker ( LNK1179 ) was for MyMainBody<>() :

 #include "MyClassA.hpp" #include "MyClassB.hpp" #include "MyClassC.hpp" #include "MyClassD.hpp" #include "MyMainBody.hpp" int main(int argc, char* argv[]) { // Use a function template for the "main-body", // implementation is "mostly-simple", instantiates // some local "MyClass" instances, they reference // each other, and do some initialization, // (~50 lines of code) // // !!! LNK1179 for `MyMainBody<>()`, mangled name is ~236 chars // return MyMainBody<MyClassA,MyClassB,MyClassC,MyClassD>(argc,argv); } 

CORRECTION:

  • Convert MyMainBody<>() from " template<> " to an explicit function , LINK SUCCESS .

THIS IS A FIX SUX , since I need EXACT-SAME-CODE for other types in other utilities, and the MyMainBody<>() implementation is non-trivial (but mostly simple) installation instances, this should be done in a certain way, in a certain order.

But hey, this is temporary work: confirmed on the MSVC2008 and MSVC2010 compilers (the same error LNK1179 for each successful link to each after applying the bypass).

THIS IS A FEEDBACK AND / OR LINKER ERROR , since the code is "simple / proper-C ++" (even C ++ 11).

So, I am happy (that I have a link after I stopped working for 2 weeks). But disappointed (that the compiler and / or linker have STUPID PROBLEM PROBLEM with SIMPLE TEMPLATE <> binding in this use case, which I could not figure out how to handle).

NEXT, "Bounty Ended" , but no one else wanted to do this (no other answers?), So nobody likes the " +100 " look, (Heavy sigh)

+36
Nov 21 '12 at 14:16
source share

There are many answers to this question, but none of them fully reflects what was happening in my code base, and what I suspect the OP saw back in 2012, when this question was asked.

This problem

An IID_* error of type IID_* easy to reproduce randomly using the #import directive with rename_namespace and named_guids .

If two #import libraries of type ed contains the same interface, as probably in the case of OP IXMLDOMImplementation , then the generated .tlh files will declare IID_IXMLDOMImplementation in both namespaces, which leads to a duplicate.

For example, the code generated for:

 #import <foo.tlb> rename_namespace("FOO") named_guids; #import <bar.tlb> rename_namespace("BAR") named_guids; 

... you can simplify something like this:

 namespace FOO { extern "C" __declspec(selectany) const GUID IID_IFOOBAR = {0}; } namespace BAR { extern "C" __declspec(selectany) const GUID IID_IFOOBAR = {0}; } 

Here is a simple replay of the RexTester problem: https://rextester.com/OLAC10112

named_guids forces IID_* , and the rename_namespace attribute transfers it to the namespace.

Unfortunately, in this case extern "C" does not work properly when it appears inside the C ++ namespace. This causes the compiler to generate multiple definitions for IID_FOOBAR in the same .obj file. DUMPBIN/SYMBOLS or the hex editor confirms duplicate characters.

The linker sees these multiple definitions and issues duplicate COMDAT diagnostics duplicate COMDAT .

Decision

Knowing that rename_namespace does not work very well with named_guids , the obvious solution would be to simply not use them together. It is probably easiest to remove the named_guids attribute and use the _uuidof() operator _uuidof() .

After removing named_guids from the #import and named_guids code, replacing all use cases of FOO::IID_IFooBar with _uuidof(FOO::IFooBar) , my COM-rich code base returns to assembly again.

+1
Oct 22 '18 at 18:45
source share

This issue is reported as an error in some specific versions of Visual Studio 2017. Try troubleshooting 15.9.1 or later to fix this problem.

+1
Jan 19 '19 at 4:37
source share

I ran into this problem when porting code (1) from MSVC to GCC. To associate the assembly with GCC, I had to provide empty implementations for some specialized template functions (2), and this led to LNK1179 on MSVC. I was able to resolve by embedding functions (3), i.e.

  • template<> template<> void LongName1<LongName2>::FunctionName(boost::library::type1 & a, const unsigned int b);
  • template<> template<> void LongName1<LongName2>::FunctionName(boost::library::type1 & a, const unsigned int b) {};
  • template<> template<> inline void LongName1<LongName2>::FunctionName(boost::library::type1 & a, const unsigned int b) {};
0
Aug 29 '13 at 8:21
source share

I needed to do C ++ -> code generation -> enable link-level linking -> no

0
Dec 27 '15 at 10:33
source share

We hope that my lame workaround will help someone: I will definitely delete all the .obj AND files of intermediate files (including at least .pch, .pdb, .tlog, .lastbuildstate and everything else, just hanging suspiciously) and rebuild from scratch.

I suggest without evidence that the presence of some files left over from the previous build leads to the fact that the problem occurs more often. On my specific build system, I delete and recreate the .vcxproj and .sln files from scratch.

My personal suspicion is that during the build / link process, there is some kind of race condition between the time during which the intermediate files are read and the time they write in a large project. Again, I have no evidence that this is true, but this is my only assumption, which seems to be consistent with all the known facts of the error.

0
Feb 16 '16 at 2:16
source share

I wrote add-ins for Outlook a few years ago, and I was asked to write another one. I immediately ran into this problem, and after going through a small troubleshooting process, I fixed mine.

It turns out that when you select a project for extension (I manually coded mine back), it creates and saves 2 objects that I did not know about: DTE and DTE80. To create interfaces that manage these objects, they are imported directly from the DLLs in stdafx.h. Since I work in Outlook, I also needed to import several interfaces: Office and Outlook.

So, seeing how this error appeared almost immediately after writing my first pieces of code, I started all over again and added one thing at a time. The project blew up the pieces in the described way right after I added:

 //Added mvc //The following #import imports MSO based on it LIBID #import "libid:2DF8D04C-5BFA-101B-BDE5-00AA0044DE52" version("2.2") lcid("0") rename_namespace("Office") raw_interfaces_only named_guids using namespace Office; //The following #import imports Outoloks Object lib based on it LIBID #import "libid:00062FFF-0000-0000-C000-000000000046" rename_namespace("Outlook") raw_interfaces_only named_guids using namespace Outlook; 

So, since I was not going to figure out the DTE stuff, I just commented on them and everything related to them:

 //The following #import imports VS Command Bars based on it LIBID // #import "libid:1CBA492E-7263-47BB-87FE-639000619B15" version("8.0") lcid("0") raw_interfaces_only named_guids //The following #import imports DTE based on it LIBID // #import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("8.0") lcid("0") raw_interfaces_only named_guids //The following #import imports DTE80 based on it LIBID // #import "libid:1A31287A-4D7D-413e-8E32-3B374931BD89" version("8.0") lcid("0") raw_interfaces_only named_guids 

After wandering around fixing compilation errors, it compiled and linked just fine. I don't suppose this will work for everyone, but it worked for me. Good luck to everyone who passes here ....

0
Jul 01 '17 at 1:59 on
source share



All Articles