Thursday, July 31, 2008

Fatal error LNK1171: unable to load c2.dll

We had an interesting problem arise where linking a Release mode static library written in C with a Fortran application using the Premier Partner edition of Visual Studio that ships with Intel Visual FORTRAN 10 would die at the linking stage. This happened late in the game as the debug mode builds of the C library did not exhibit this error. To make matters worse, if users had any other version of Visual Studio with just the Intel Visual FORTRAN Compiler Integration installed, no such problems arose.

Our first step was to install the Platform SDK: no joy. The second step was to manually copy the DLL's required (there are actually 3 DLL's you need) from a working install to the non-working install: success!

So, what could possibly be the problem here?

No amount of searching could turn up the issue, so a ticket was opened with Intel's Premier Support. Well, we should have done this from the beginning because it appears that the compiler writers themselves know a lot about the compiler toolchain; fancy that. The (relevant) response from Intel:
c2.dll is used by the Microsoft Visual C++ compiler to perform whole-program optimization. Might it be that this "release" C library was compiled with that option? If so, you will require Visual C++ to be installed in order to build using that library.

My advice is that if you know you will be linking a C library on a system with only Visual Studio Premier Partner Edition installed that you be sure that Whole Program Optimization is disabled, as otherwise Fortran programmers will not be able to use it.
Sure enough, disabling Whole Program Optimization on the Release mode builds of the C static library solved all of our issues.

4 comments:

Ben said...

Just wanted to let you know that even 3+ years after you posted this, it has helped me out. I had the EXACT same scenario. Debug static C lib works, release static C lib gives the "can't load C2.dll". We also use Intel Visual Fortran. Turned off WPO for the release config, and everything works! Thanks!

den said...

Just had the same problem using VS2011, thanks for the post

Anonymous said...

A simpler solution is to change the order of additional libraries that are configured to be linked.

Check this out: http://bytes.com/topic/net/answers/265260-whole-program-optimization-results-lnk1171-error-cannot-find-c2-dll

Christopher said...

Interesting! I'll give that a try the next time I run into this problem (I believe Composer Studio no longer has that issue).