- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page