Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29253 Discussions

LNK2005 error when compiling for Debug x64 (mixed C++/Fortran)

Vincent_S_1
Beginner
1,559 Views

Hi all, I'm attempting to recompile a mixed C++/Fortran project for a x64 platform / Debug configuration but keep running into a LNK2005 error. The Fortran code is compiled to a static library while the C++ code -- which calls the Fortran code -- is compiled to a dynamic library. The error occurs when I attempt to compile the C++ code:

1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: atanf already defined in MyFortranLibrary.lib(atanf_stub.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: atan2f already defined in MyFortranLibrary.lib(atan2f_stub.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: sqrtf already defined in MyFortranLibrary.lib(sqrtf_stub.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: cosf already defined in MyFortranLibrary.lib(cosf_stub.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: sinf already defined in MyFortranLibrary.lib(sinf_stub.obj)

Here, "MyFortranLibrary.lib" is the compiled Fortran library.

Things I've tried:

  • Added ..\Intel\Composer XE 2013 SP1\compiler\lib\intel64 directory to both projects' library directories
  • Set Runtime Library > Multithread Debug DLL for both projects
  • Cleaned and rebuilt projects

This seems to be the most prevalent solution (at least as far as I know), but doesn't seem to work in my case. I am able to compile for x32/Debug, x32/Release, and x64/Release. Please let me know if I've missed any information that may help diagnose the problem. Thanks!

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,559 Views

Please attach either a ZIP of the buildog.htm from your MyFortranLib project or the .vfproj file of that project. It seems possible that you are somehow telling the librarian to include in your library the Intel math library, rather than letting that get resolved at link time.

0 Kudos
mecej4
Honored Contributor III
1,559 Views

I don't see why your static library, MyFortranLibrary, contains atanf_stub.obj, etc. Try listing the OBJ files contained in the library (LIB /LIST). Where did these files (atanf_stub.obj, etc.) come from?

You can try removing these OBJ files from your library and try again to build the C++ DLL.

0 Kudos
Vincent_S_1
Beginner
1,559 Views

Update: I added MSVCRT.lib as an additional linker dependency to the C++ project, which seems to have resolved the issue. Steve, I think you're right (because I include libmmt.lib as an additional dependency in the Fortran project), but according to others on my team this was done to resolve a different linker error. Makes me a little nervous since it seems dependencies were being added/ignored willy-nilly just to prevent linker errors (like what I'm doing now), but I'll see if I can clean up the project properties when I have the time. As it stands, the projects now compile and run.

0 Kudos
Steven_L_Intel1
Employee
1,559 Views

You should never have to add msvcrt.lib as a dependency. Instead, use the appropriate project settings to make sure the proper and consistent libraries are linked in. For your Fortran library project, the Fortran > Libraries > Use runtime library setting should match the C++ one under Code Generation > Runtime Library.

0 Kudos
Reply