Undefined reference when calling an external function of the same module [duplicate] - module

This question already has answers here:
Why is this a function declared inside the module and then used somewhere else in the same module not seen by the linker?
(2 answers)
Undefined reference to procedure defined in the same module [duplicate]
(1 answer)
Fortran function in a module not found by subroutine in the same module [duplicate]
(1 answer)
Closed 2 years ago.
I have a number of functions in a module, and I need one function to use other of the same module as the input of of a third function.
FUNCTION FUN2(W)
use gabqs, only: GABQ2
IMPLICIT REAL*8 (A-H,O-Z)
! REAL*8 W
EXTERNAL FUN3
R1 = 1.e-5
R2 = 10.e0
TOL = 1.E-2
CALL GABQ2(FUN3,R1,R2,SUM2,TOL,IER)
Fun2=sum2*W
RETURN
END
FUNCTION FUN3(R)
use dielectricFun, only: elflev
IMPLICIT REAL*8 (A-H,O-Z)
REAL*8 K,W
PI=3.1415926536
CALL elflev(w,k,r,ximelf)
fun3=ximelf*4.d0*pi*(r**2.d0)
RETURN
END
I can compile the module but when I compile the main program i get an error in the module where the two functions are:
.\integralfun.o:integralFun.F90:(.text+0x16c): undefined reference to `fun3_'
I have all the use statement in the main program.

Related

Is it possible to evaluate a variable inside a call read() in karate? [duplicate]

This question already has an answer here:
whats syntax for calling other scenario in same feature file?
(1 answer)
Closed 1 year ago.
demoType is a variable and I want the content of this variable to be what is evaluated in the following expression:
* def call read(demoType)
On the contrary, it tries to evaluate the name of the variable and not its content.
There is no such thing as def call.
Maybe you were trying:
* call read(demoType)
Or:
* def temp = call read(demoType)
Make sure you are on the latest version of Karate. And read the docs: https://github.com/intuit/karate#call-vs-read

Fortran: class in abstract interface [duplicate]

This question already has answers here:
Why is the type not accessible?
(2 answers)
Closed 6 years ago.
Using cygwin64 on Windows this program won't compile:
program test
implicit none
!define my type
type myType
real::foo
integer::bar
end type myType
!define an operator for this type
interface operator (>)
logical function compare(a,b)
type(myType),intent(in) :: a,b
compare = a%foo>b%foo
end function compare
end interface operator (>)
!simple example of operator usage
type(myType) :: tfoo, tbar
tfoo = card(1.,2); tbar = card(3.,4)
print*, tfoo>tbar
end program test
gfortran (only argument is "std=f2008") tells me:
type(myType),intent(in) :: a,b
1
Error: Derived type ‘mytype’ at (1) is being used before it is defined
which is confusing to me, since the type is defined right before the operator. I'm relatively new to Fortran, so this example code might have some more errors.
The same problem occurred here, but encapsulating myType in a separate module did not resolve the issue.
There are several issues with your code, but this particular error is because myType is in the host scope, but not in the interface block. The solution is to either place the derived type in a separate module as suggested in the linked thread, or import the derived type from the host scoping unit:
interface operator (>)
logical function compare(a,b)
import myType
type(myType),intent(in) :: a,b
end function compare
end interface operator (>)
This is described in the Fortran 2008 Standard, Cl. 12.4.3.3 "IMPORT statement":
1 The IMPORT statement specifies that the named entities from the host scoping unit are accessible in the interface
body by host association. An entity that is imported in this manner and is defined in the host scoping unit shall be
explicitly declared prior to the interface body.
An interface block may not have executable statements included - so the assignment you have there is not valid. Furthermore, card is not defined in your code.

Using a function inside another function inside a module [duplicate]

This question already has answers here:
Why is this a function declared inside the module and then used somewhere else in the same module not seen by the linker?
(2 answers)
Fortran function in a module not found by subroutine in the same module [duplicate]
(1 answer)
Closed 3 years ago.
I have functions and subroutines in my module. Then I use that module inside the main program. But inside my module there is function where I call another function. While I compile that it says undefined reference in Fortran.
module A
implicit none
real*8 :: k(1:4),ls(1:4)
contains
function B(p,q)
implicit none
real*8 :: p,q,B
B=p+q
end function B
subroutine C(u,v,res)
implicit none
real*8 :: u,v,res,B
res=B(u,v)
end subroutine
end module A
program main
use A
implicit none
real*8 :: Out
call C(4.d0,3.d0,out)
write(*,*) out
end program main
I would like to get 7.0d0 ,but I am getting undefined reference in Fortran for B.

Fortran function in a module not found by subroutine in the same module [duplicate]

This question already has answers here:
Why is this a function declared inside the module and then used somewhere else in the same module not seen by the linker?
(2 answers)
Closed 4 years ago.
I am writing a module in Fortran90, Mainly I defined a function inside the module, and a subroutine that uses the function. Here's an excerpt of the module
module Mesh_io
implicit none
private
contains
integer function findkey ( )
content of this function
end function
subroutine getNumber_Mesh ()
integer :: findkey
content of the routine
end subroutine getNumber_Mesh
end module
When compiling I get the following output:
objects/Main.o: In function `__mesh_io_MOD_getnumber_mesh':
Main.f90:(.text+0x9e): undefined reference to `findkey_'
As you can see the function is contained in the module, but for some reason the compiler can not find it.
With the declaration of findkey inside the subroutine getNumber_Mesh() you are creating a local variable findkey that hides the function.
With modules, it is not required to declare the return value of functions (of module functions). Simply removing the declaration should do the trick.

Fortran link modules for precision and global variable types

I am new to Fortran and trying to understand if the following is possible. My idea to structure the program is to declare the precision and variable types in one module. Then make use of those variables without declaring again the type in other modules or the main program.
module pre
implicit none
INTEGER, PARAMETER :: sp=SELECTED_REAL_KIND(6,37)
INTEGER, PARAMETER :: dp=SELECTED_REAL_KIND(15,307)
INTEGER, PARAMETER :: qp=SELECTED_REAL_KIND(33,4931)
REAL(dp), PARAMETER :: pi = 4.*ATAN(1.)
REAL(dp) :: H
REAL(dp) :: M
REAL(dp) :: KR
end module pre
Now I want to make use of all the variables in another module that contains one or more functions, such as:
module hon
use pre
implicit none
contains
function KE(H,M) result(KR)
KR = 2*PI/H/M
end function KE
end module hon
Then I use gfortran in this order:
gfortran -c mod_pre.f90
gfortran -c mod_hon.f90
Since 'module pre' is part of 'module hon' I compile in order, but gfortran shows an error.
With the code above I understand the variable types and parameters should have been included by USE; But the message I get from gfortran is that none of my variables have IMPLICIT type when I try to compile 'module hon'.
Could somebody clarify the problem or suggest a solution? I would like to avoid having my variables scattered in multiple modules.
Thanks!
In the function statement, the result(kr) says that the function result has name kr. This function result is not the same thing as the module variable kr. In particular, this function result makes inaccessible the module variable.
The function result is specific to the function itself and its properties must be declared within the function subprogram.
Similarly, the dummy arguments of the function, H and M, are distinct from the module variables and need to be declared in the function subprogram.
Beyond that, you perhaps have similar concerns to this other question.
To be clear, it isn't possible to say something like "all function results called kr and all dummy arguments called H or M have these characteristics". Each individual object must be given the properties.
However, although I don't recommend this, this is a situation where literal text inclusion (using a preprocessor or include file) could help you:
function ke(H, M) result (kr)
include 'resdummydecls'
...
end function
where the file has the declarations.