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

Creating a static library

plyoungmin
Beginner
2,165 Views
Hi,
I'm having a hard time creating my own math library.
Here's what I did.
1. Build a static library by selecting the Fortran Static Library project type.
So 'my_lib.lib' is created in the folder visual studio 2005>projects>my_lib>my_lib>x86>debug.
It includes, among others, module 'matrix'.
2. Then add 'my_lib.lib' to the main project via project>add existing item>choose 'my_lib.lib'
The main program is as follows.

program main

use matrix

implicit none
...
3. Build the solution.
Then I get the following error message.

Error 1 Error: Error in opening the compiled module file. Check INCLUDE paths. [MATRIX]

Since I'm a beginner in Fortran, it's hard to figure out what's wrong, and the manual is not that helpful.
I tried
(1) tools>options>fortran>general>specify library directory as the foler where 'my_lib.lib' is located
(visual studio 2005>projects>my_lib>my_lib>x86>debug )


(2) project>properties>linker>input>additional dependencies>type 'my_lib.lib'
But it still doesn't work.


Thanks.
0 Kudos
1 Solution
Les_Neilson
Valued Contributor II
2,165 Views
Do not cofuse the compile step with the link step.
The message you show is a compile message.
You need to tell the compilerwhere to find the module that "program" is USEing.

In the project when you compile your module there is an "outputdirectory" When youbuild your module project the .mod file(s) and the .lib are placed there.

So in Projects->Properties under the Fortran->General dialog you need to put that directoryin "Additional include files" so that the compiler can access the .mod file for "program" (or whatever else"uses" the module)

Then inthe linker step itneeds access to the .lib file in order to produce the final product - exe or whatever.

hth
Les

View solution in original post

0 Kudos
5 Replies
mecej4
Honored Contributor III
2,165 Views
You have a little confusion as to the roles of module and library files in the build process. Module files are sought by the compiler when it encounters a USE statement. After all source files have been compiled, the linker is given control and it looks for library files.

Having the library file in the correct place does nothing for the compiler and having the module file in the correct place does nothing for the linker.
0 Kudos
David_Mccabe
Beginner
2,165 Views
I am using VS2010, to assosiate the .lib project with the .exe project in the solution, you right click the .exe project icon, select Project Dependencies, then click the name of the .lib project.

hth
0 Kudos
Les_Neilson
Valued Contributor II
2,166 Views
Do not cofuse the compile step with the link step.
The message you show is a compile message.
You need to tell the compilerwhere to find the module that "program" is USEing.

In the project when you compile your module there is an "outputdirectory" When youbuild your module project the .mod file(s) and the .lib are placed there.

So in Projects->Properties under the Fortran->General dialog you need to put that directoryin "Additional include files" so that the compiler can access the .mod file for "program" (or whatever else"uses" the module)

Then inthe linker step itneeds access to the .lib file in order to produce the final product - exe or whatever.

hth
Les
0 Kudos
plyoungmin
Beginner
2,165 Views
Thank you. It works.
0 Kudos
dboggs
New Contributor I
2,165 Views

Although this issue is apparently solved, I sympathise with plyuongmin. Building a complete solution, complete with multiple source files, module files, external and internal subroutines, multiple static libraries, and multiple dynamic link libraries, is complicated. And when one is trying to learn Visual Studio along with Fortran it gets worse. And he is right, the documentation is not helpful.

It would be very helpful if someone at Intel could write a chapter in the user's guide to cover this.

0 Kudos
Reply