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

mixed language issues

knitro
Beginner
1,150 Views
I am developing an application for others to use which is a mixture of C and Fortran. Essentially, the user will be provided a library file which they can call from a C program (however, the library also has some Fortran code in it). My question is this. Is there a way to link the library file in such a way such that the user does NOT need to have access to the Visual Fortran libraries (like DFOR.LIB) in order to successfully call/use the library I have created which is a mixture of Fortran and C? I am thinking along the lines of something like a static link which creates a library or object file which already has everything so the user doesn't need any of the Fortran libraries. I know that one is not permitted to distribute Fortran libraries like DFOR.LIB so I am looking for a legally viable solution. As much as I wish I could count on my users to have Visual Fortran, unfortunately it is not that common and so I am looking for a solution which does not require this. Otherwise I am stuck using f2c to create a complete C library which is not what I desire (it slows down my code significantly). I am relatively new to Windows having done most my work on Linux/Unix platforms. Thanks.
0 Kudos
7 Replies
Steven_L_Intel1
Employee
1,150 Views
A library is not linked, so you can't "static link" it. The recommended method for doing this is to create a DLL and distribute that, along with its export library. You can distribute DFORRT.DLL along with it, or have the end-user download and install the latest redistributables kit from our web site.

Steve
0 Kudos
knitro
Beginner
1,150 Views
Steve,

Thanks for your prompt reply. I agree I was using the term library where I should have used object file. I have read through the Visual Fortran Programmer's Guide and am trying to create a dll for the first time. I use the following command

df /dll /link /out:program.dll a.obj b.obj c.obj

According to the Programmer's Guide this should create a dll AND an import library file (program.lib) which can then be linked against to create an executable. The above commands are successful at creating program.dll however they do not create any import library file. Do you have any suggestions on why this is the case? Much thanks.
0 Kudos
Steven_L_Intel1
Employee
1,150 Views
You won't get an export library unless you have specified one or more symbols to export. You can do this with !DEC$ ATTRIBUTES DLLEXPORT directives or with a .DEF file.

Steve
0 Kudos
knitro
Beginner
1,150 Views
In the Programmer's Manual it says that one needs an import library to link with applications that call the dll. Is this true?

What is a !DEC$ ATTRIBUTES DLLEXPORT directive or a .DEF file? Can you point me to some documentation on this or to some documentation which explains how to create the needed import libraries? I cannot find anything on this in the Visual Fortran documentation since this documentation states that these libraries are created automatically when one uses the /dll flag (see below). Much thanks.


******

The text below is from the Visual Fortran Programmer's Guide on creating dll's.

If you build a DLL from the command line or use an exported makefile, you must specify the /dll option. For example, if the Fortran DLL source code is in the file f90arr.f90, use the following command line:

DF /dll f90arr.f90

This command creates:

- A DLL named f90arr.dll.
- An import library, f90arr.lib, that you must link with applications that call your DLL.
0 Kudos
Steven_L_Intel1
Employee
1,150 Views
You need to read the chapter in the Programmer's Guide on creating and using DLLs to learn about DLLEXPORT. This is required if you want anyone to be able to call the routines in your DLL, otherwise no symbols are made visible.

An import library is needed for linking to DLLs, but not for use in languages such as Visual Basic that do the binding at run-time.

Steve
0 Kudos
knitro
Beginner
1,150 Views
Hi Steve,

Thanks for your help. I have been reading through the Programmer's Manual on using and creating dll's but at least the version I have does not explain how to use dllexport or how to create an import library. All the text I can find in scouring this chapter indicates that the import library is automotically created along with the dll. I would love to find some detailed documentation for those who are not too familiar with Windows which takes one through the complete process of creating a dll including the import library.

How does the fact that I have both C and Fortran routines in my dll affect things. Things are set up so that the routine in the dll that gets called by the user is a C routine (which then in turn calls a bunch of Fortran routines). Should I be creating a C dll or a Fortran dll? Or is it a problem having both C and Fortran routines in the same dll?
0 Kudos
Steven_L_Intel1
Employee
1,150 Views
The manual doesn't explicitly say how to create an import library - the linker creates it automatically if there is at least one exported symbol in the DLL. If I understand you correctly, the Fortran code is not meant to be visible to the users of the DLL - it is called only from the C code. If that's so, then you need to use the __pragma(dllexport) (I think) attribute on your C routine(s) to make them visible.

Chapter 8 of the Programmer's Guide covers DLLs from the Fortran perspective. There is no problem having Fortran and C routines in the same DLL.

Steve
0 Kudos
Reply