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[]) {
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)