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

Linking C++ with Fortran static library

gdumont
Beginner
839 Views
Hi,

First off, I am using MS VS C++ 2003 and Intel Fortran 10.0.025.

I have a C++ Multi-threaded dll in which I call Fortran subroutines that are in a multi-threaded static library. If I get this right, this multi-threaded library has to link to ifconsol.lib, libifcoremt.lib and libmmt.lib. However, because my C++ dll is linking to msvcrt.lib(.dll), I always get error messages at compile time (unresolved or multiply defined symbols) or at run time (missing dlls). I figured out that to get it all work I have to link the Fortran library to libifcoremd.lib and libmmd.lib instead of "mt" and include the associated dlls in the path of my C++ dll. My concern is that I recently added a Fortran 90 project to my Fortran library solution, which was composed fo two Fortran 77 projects and since then I need to include the intel dlls. Before the insertion of the Fortran 90 project and the conversion from Intel 8.0 to 10.0 the library was only linked to limmt.lib libifcoremt.lib and there was no need to include dlls.

So I was wondering if there was a reason for that? Is there anyway I could only use static libraries?

I figured that libmmt.lib conflicts with msvcrt.lib because of missing symbols, i.e. ___argc and ___argv which are referenced in function _for_rtl_init_. . Maybe this function isnt used by F77 but is by F90? Also, why would I need to include the libmmd.dll if I linked my static library with libmmt.lib and that everything built fine?

Any help is appreciated

Regards,

Guillaume
0 Kudos
2 Replies
TimP
Honored Contributor III
839 Views
Mixing f90 with f77 code doesn't require additional libraries. It looks like you have inadvertently compiled some part of the project with debug flags.
0 Kudos
gdumont
Beginner
839 Views
Thanks for your reply.

According to the Intel Compiler Manual:

You must take care to choose the same type of run-time libraries in both your Fortran and C project. For example, if you select Multithreaded DLL in your Fortran project, you must select Multithreaded DLL in your C project. Otherwise, when your build your mixed Fortran/C application, you will receive errors from the Linker regarding undefined and/or duplicate symbols.

Thus if my C++ project is using the Multi-threaded dll run-time librairies I should use the appropriate Fortran librairies for my Fortran project. More precisely, if I use:

msvcrt.lib in C++

then I shoudl use

libmmd.lib and libifcoremd.lib in Fortran. This makes sense to me, but I am wondering why it used to work before with

libmmt.lib and libifcoremt.lib ????

The problem is that I would like not to have to distribute the Intel Fortran DLLs with my exectuable.





0 Kudos
Reply