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

CALLING FUNCTION from Static Libraries

ZZA
Beginner
1,759 Views

Hello everyone,

I'm new to Intel Visual Fortran recently, and getting some troubles when using it.

Currently I need to design a small program that can plot simple shapes (points, lines, dot lines, add words etc.) onto files and output them into picture format (jpg/png/gif). It is NOT necessary to view these files in some output window, but just saving them onto disk is OK for me.
I searched in Google and found a library called "PLPlot" that can help me with this task. However, I'm getting into troubles during the procedure.  My currect OS is XP, with VS 2010 and IVF 2011.

1) I downloaded someone's builed PLPlot library, which contains static library (.lib) files and three module files (.mod), so I included their path in "project property->General->Additional Include Directory" and "Property->Linker->General->Additional Library Directories", and directly using "CALL FUNCTIONNAME" in main.f.
But I got "ERROR LNK2019: unresolved external symbol _FUNCTIONNAME referenced in _MAIN".
I checked it up in the user manual and lots of online documents, but I can't find a standard example or tutorial for USING STATIC LIBRARY in Intel Visual Fortran, so I don't know if anything is missing.
Is there anyone can write me a simple example of CALLING FUNCTIONS from static library and modules?

2) I need to check if the downloaded builded library works fine or not. If it works not so properly (after I follow the correct steps from question (1)) then I need to compile the library again myself or try other library. Is there any build-in library functions in Intel Visual Fortran to help me accomplish my task?

I appreciate your help.
Thank you a lot!

zza

0 Kudos
6 Replies
jimdempseyatthecove
Honored Contributor III
1,759 Views

"CALL FUNCTIONNAME" is a euphemism, meaning there is no subroutine or function named "FUNCTIONNAME", rather, you are supposed to look at the library documentation to obtain the correct name and calling conventions, then substitute the name and calling format (subroutine or function) along with appropriate args. Example:

CALL PieSlice(X, Y, startAngle, endAngle, Radius)

The above subroutine is not likely to be in your library, I used it as an example.

Jim Dempsey

0 Kudos
ZZA
Beginner
1,759 Views

jimdempseyatthecove wrote:

"CALL FUNCTIONNAME" is a euphemism, meaning there is no subroutine or function named "FUNCTIONNAME", rather, you are supposed to look at the library documentation to obtain the correct name and calling conventions, then substitute the name and calling format (subroutine or function) along with appropriate args. Example:

CALL PieSlice(X, Y, startAngle, endAngle, Radius)

The above subroutine is not likely to be in your library, I used it as an example.

Jim Dempsey

Hi Jim,

Thanks first for your answer.

The "CALL FUNCTIONNAME" is only what I refer to a function generally.

My main.f would look like this:

Program Test

.....

Call plcon(X,Y,Z)

END

While "plcon(real, real, real)" is a function named from the library documents.

But I got the erro LNK2019 by writing my code like above, thus why I came for help.

Could you please show me if there is any setting or steps that I made it wrong?

Thanks a lot!

zza

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,759 Views

You may need to use (declare) an interface to the subroutine:

INTERFACE
SUBROUTINE plcon(X, Y, Z) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING
IMPLICIT NONE
REAL (C_FLOAT), VALUE :: X, Y, Z
END SUBROUTINE plcon
END INTERFACE

Note, if this is a popular library, then someone may have written a module file that contains the FORTRAN interface declarations. In this case you simply add "USE WhateverThisModuleNameIsCalled" to your subroutines and functions that make calls to this library.

Jim Dempsey

0 Kudos
ZZA
Beginner
1,759 Views

jimdempseyatthecove wrote:

You may need to use (declare) an interface to the subroutine:

INTERFACE
SUBROUTINE plcon(X, Y, Z) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING
IMPLICIT NONE
REAL (C_FLOAT), VALUE :: X, Y, Z
END SUBROUTINE plcon
END INTERFACE

Note, if this is a popular library, then someone may have written a module file that contains the FORTRAN interface declarations. In this case you simply add "USE WhateverThisModuleNameIsCalled" to your subroutines and functions that make calls to this library.

Jim Dempsey

Thanks for your answer!

I will look into code to try digging these part out.

Best regards,

zza

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,759 Views

If you need examples of interfaces, the best place to look is in the IVF include folder (e.g. ifopengl.f90).

Jim Dempsey

0 Kudos
IanH
Honored Contributor III
1,759 Views

In the OP, there's mention of mod files, which suggests that the procedure being called is a module procedure.  If that is the case then the OP must not provide an interface block.

But they would need a USE statement for the appropriate Fortran module that holds the FUNCTIONNAME procedure at the top of your program unit that references the procedure.  The mod files are named after the module that they were compiled from.

Also, in addition to specifying the directory that holds the lib file you also need to specify the lib file names under Linker > Input > Additional dependencies.

0 Kudos
Reply