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

Using module and source files from other project

guillaume_charland
2,269 Views

Hi. I am relatively new to Fortran and visual studio, but i have some experience with other language (Java , C , C++ , perl, PHP ...). I wanted to know how to use source code from other project into my current project.

Lets say i havea project with a Module named Tool.I want to use Tool in other project without having tocopy the source file of Tool every where i want to use it.

In C , i would use something like #include "PATH to Tool "

But , i dont know how to do this in Fortran. For now i am using the USE statement. Witch gave me a check INCLUDE path error.

I have then add, in Visual Studio, the path to Tool project folderwitch content all the Tool filesin (menu : tool -> options -> intel visualfortran -> compiler)
To Executables , Librairie , Includes.

Those paths lead to all the source code .f90 (\Tool folder)and to the .mod(\Tool\Debug)

Now i can compile other program that use Tool. And can also use the Type that are defined in Tool. But i cant use anyway of the function or subroutine. I get a unresolved external symbol error.

So now i am a little lost. What does i need to do, to be able to usefunction that are in my Tool module.

I know i could maybe use a DLL, but i am in developpement stage and i dont want to have to recompile my source each time i need to change something in my Tool module

Thanks a lot for the help

P.S i dont know if i am clear enouh, if you need more details or source code let me know



0 Kudos
4 Replies
TimP
Honored Contributor III
2,269 Views
According to Fortran terminology, MODULE has a specific meaning, and for it the USE has a function analogous to #include. Fortran also has available the older style INCLUDE, which copies source text verbatim. In addition, the cpp-like #include functionality is enabled by turning on the /Qfpp pre-processing option, which can be done in the Visual Studio properties>Fortran. Both USE and #include observe the include file path, set up the same way as in C++.
0 Kudos
guillaume_charland
2,269 Views
Quoting - tim18
According to Fortran terminology, MODULE has a specific meaning, and for it the USE has a function analogous to #include. Fortran also has available the older style INCLUDE, which copies source text verbatim. In addition, the cpp-like #include functionality is enabled by turning on the /Qfpp pre-processing option, which can be done in the Visual Studio properties>Fortran. Both USE and #include observe the include file path, set up the same way as in C++.

Ok, well i am using the MODULE term in the same way as a class in Java or C++. So its one file for one class, or MODULE.

I understand that USE as the same function as #include. But since you give the name of the module (or class) and not the position of the file in the file system, i had supose that it was supose to be in the same Project.Can you use the USE statement like this :

USE "PATH to ToolTool" ???


Oo shouldi use the /Qfpp pre-processing optionand do something like this :

MODULE Work

#Include "PATH to ToolTool.f90"
USE Tool

IMPLICIT NONE

...

!Use Tool function and Subroutine
...

END MODULE Work


And thanks for the fast response!

0 Kudos
Steven_L_Intel1
Employee
2,269 Views
Fortran modules have no exact counterpart in C++. In the USE statement, you name the module, which has nothing to say about where the compiler goes to look for it. To specify location, you have to do it outside the source. In the Intel compiler, that is done through the path for INCLUDE.

So on a per-project basis, you would add the path to the folder containing the .mod files to the project property for "additional INCLUDE directories". You can also add it, for all projects, in Tools > Options > Intel Visual Fortran > Compilers > Include files.

I understand that this is not as simple as it should be, but modules are not simple text files that get included. Ideally, if you made one Fortran project a dependent of a second, its "output" directory would be added to the INCLUDE path of the parent - I have a feature request in for that.
0 Kudos
Les_Neilson
Valued Contributor II
2,269 Views

Just a thought - if you don't really mean Fortran module.

If you have a fortran source file,for example/TOOL.f90
and you have a project in and you want to have TOOL.f90 added to that project (without copying it everywhere)
then in Visual Studio Solution Explorer for your project,all you need do is
(I think you may have to click on the project"Source Files" first to highlight it)

(a) click on Project -> Add Existing Item
(b) navigate to /TOOL.f90 click on it and click on "Add"

Then in your project code all you need do is call any subroutines/functions that are in TOOL.f90

An alternative if you have lots of files in which you want to call from your project then your project would create a lib (say) and that lib would be added to the list of libs under Project->Properties->Linker->Input->Additional Dependencies
and the path to it would be on
Project->Properties->Linker->General->Additional Library Directories

Les
0 Kudos
Reply