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

Building a DLL with C and Fortran routines

Arjen_Markus
Honored Contributor II
1,031 Views
Hello,

I am trying to build a DLL using Intel Fortran 11.1 and MSVC 9.0 that combines
C and Fortran routines.

Since I can not put all the source files in the same project, I have aproject with
the C source files that will build into a DLL and a project with the Fortran files that
will deliver an ordinary library. This gets included in the DLL.

When I compile and link this, I get the error message that _MAIN__ is missing.
The DLL is still created because of the /force option. So far so good.

Using it in a small test program, however, causes the program to fail: it was not
initialised properly.

This has to do with the runtime libraries I have selected for the Fortran library:
Multithreaded, instead of "Multithreaded, DLL".

If I choose the latter, the program does work, but then I get dependencies on
a host ofIntel Fortran libraries, such as libifcoremd.dll. This is something I
want to prevent.

I can turn the Fortran library into a DLL, but then I have two DLLs to worry
about instead of one. I would like to keep both the C and the Fortran routines
in one single DLL.

Is that possible or am I doomed tocreate separate DLLs?

Regards,

Arjen

PS I hope I have described the problem clear enough. I could probably
create a small example of the problem, but I have nottaken the time yet.

0 Kudos
7 Replies
anthonyrichards
New Contributor III
1,031 Views
If _MAIN__ is missing, clearly one or other of the projects you are trying to build must be set up as an .EXE (WIN32 application), so it is looking for a PROGRAM ...end PROGRAM section of code somewhere in your project files.

Does the C compiler produce COFF object files? If so, they should be no different from the ones produced by the Fortran compiler for a Windows application, and can therefore be included in the Fortran library project and they will then be linked in to the library.
0 Kudos
Arjen_Markus
Honored Contributor II
1,031 Views
The main program is written in C, so it does not know anything about _MAIN__.
But the Fortran library refers to _MAIN__ via the runtime libraries it refers to.

Regards,

Arjen
0 Kudos
anthonyrichards
New Contributor III
1,031 Views
What C compiler are you using? I can only echo this found in a C-programming forum

"The last bizarre type of linker error is a complain about an "undefined reference to main". This particular linker error differs from the other in that it may have nothing to do with including object files or having the correct paths to your libraries. Instead, it means that the linker tried to create an executable and couldn't figure out where the main() function was located. This can happen if you forget to include the main function at all, or if you attempt to compile code that was never meant to be a stand-alone executable (for instance, if you tried to compile a library)."
0 Kudos
Arjen_Markus
Honored Contributor II
1,031 Views

MS Visual C/C++ 9.0

The only change froma successful build is the use of the multithreaded (static) libraries instead of
the DLL versions.

Regards,

Arjen

0 Kudos
TimP
Honored Contributor III
1,031 Views
If your Fortran project is the normal /MT, the companion C++ project should be set to that mode as well.
0 Kudos
Arjen_Markus
Honored Contributor II
1,031 Views
Hm, I will try that - thanks

Regards,

Arjen
0 Kudos
Arjen_Markus
Honored Contributor II
1,031 Views
Tim,

this does indeed work! Thanks for the advice.

Regards,

Arjen
0 Kudos
Reply