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

error LNK2019: unresolved external symbol

h_amini
Beginner
6,832 Views

To have explicit interfaces I put all the subroutines and functions of my program inside MODULE SUBPROGRAMS, but got LNK2019 errors like:

TEMP.obj : error LNK2019: unresolved external symbol _F1 referenced in function

_SUBPROGRAMS_mp_VA1.

F1 and VA1 are function and subroutine in respect, and temp.f is compiled on 32 bit platform.

Any advice would be very much appreciated.

Hamid

0 Kudos
1 Solution
Steven_L_Intel1
Employee
6,832 Views
I see. The problem is that you have a declaration of CRACK as INTEGER in subroutine MESH, where CRACK is a module procedure. As a module procedure, CRACK defines its own explicit interface. When you have a separate declaration of CRACK as INTEGER, that means that CRACK is an external procedure and it hides the module procedure.

Remove all declarations of the module procedures in other program units - let the module serve as the declaration.

View solution in original post

0 Kudos
8 Replies
Steven_L_Intel1
Employee
6,832 Views
You need to link against the object file created when SUBPROGRAMS was compiled.
0 Kudos
h_amini
Beginner
6,832 Views

Many thanks Steve but Ive never done that. Could you explain more or make an example please.

I have to leave my office now so will reply you tomorrow if required.

Hamid

0 Kudos
Steven_L_Intel1
Employee
6,832 Views
If you are building from within Visual Studio, and the source of the module and the source of the program using the module are in the same project, this is done for you automatically.

If you are building from the command line, you'd do something like this:

ifort -c modulefile.f90
ifort mainprog.f90 modulefile.obj

If this doesn't help, please show me how you are building the application.
0 Kudos
h_amini
Beginner
6,832 Views

Many thanks again. All the sources were in temp.f and I used the command line to compile it (ifort temp.f)when got the errors.

Now if I separate the modules and the main program into tempM.f and tempP.f and compile with the commands you said, I get the same errors.

ifort c tempM.f

ifort tempP.f tempM.obj

The problem is solved when in temp.f I put all the functions inside the source of the program and keep just the subroutines in module SUBPROGRAMS.

Hamid

0 Kudos
Steven_L_Intel1
Employee
6,832 Views
I think I am going to need to see an example of what didn't work. Please attach a ZIP of the sources that show the problem.
0 Kudos
h_amini
Beginner
6,832 Views

I am attaching a self-contained test. The entire source is in tempS.f, and the module and the program are pastedto tempMS.f and tempPS.f

The error I am getting now is:

tempS.obj : error LNK2019: unresolved external symbol _CRACK referenced in funct

ion _SUBPROGRAMS_mp_MESH

tempS.exe : fatal error LNK1120: 1 unresolved externals

Hamid

0 Kudos
Steven_L_Intel1
Employee
6,833 Views
I see. The problem is that you have a declaration of CRACK as INTEGER in subroutine MESH, where CRACK is a module procedure. As a module procedure, CRACK defines its own explicit interface. When you have a separate declaration of CRACK as INTEGER, that means that CRACK is an external procedure and it hides the module procedure.

Remove all declarations of the module procedures in other program units - let the module serve as the declaration.
0 Kudos
h_amini
Beginner
6,832 Views

Yes, you could solve the problem. Many many thanks.

Hamid

0 Kudos
Reply