Dear Dave
I started following the approach that you suggested. In particular, I created a trial solution in Visual studio containing two projects: a Win32 Console containing the file:
//Source.c
#include <stdio.h>
void pythagoras(float a, float b, float *c);
main()
{
float c;
pythagoras(30, 40, &c);
printf(“Hypotenuse if sides 30, 40 is: %f\n”, c);
}
and a static library using PGI Visual Fortran containing the file:
!Lib.f90
subroutine pythagoras (c1, c2, hy ) bind(c)
use, intrinsic :: iso_c_binding, only : c_float
implicit none
real(c_float), value, intent(in) :: c1, c2
real(c_float), intent(out) :: hy
hy =sqrt c12 + c22 ! No, I didn’t forget the parenthesis, but if I put them after sqrt it doesn’t let me upload the post on this forum for some obscure reason.
end subroutine pythagoras
Then, I compiled the static library and I linked it to the main project. When I try to compile the overall solution I get the following errors:
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol ISO_C_BINDING ConsoleApplication1 C:\Users\rt058861\Documents\Work\Tutorial_C++\tutorial13\ConsoleApplication1\ConsoleApplication1\PVFProject1.lib(Lib.obj) 1
Error LNK2001 unresolved external symbol __pgdbg_stub ConsoleApplication1 C:\Users\rt058861\Documents\Work\Tutorial_C++\tutorial13\ConsoleApplication1\ConsoleApplication1\PVFProject1.lib(Lib.obj) 1
Error LNK2001 unresolved external symbol f90_compiled ConsoleApplication1 C:\Users\rt058861\Documents\Work\Tutorial_C++\tutorial13\ConsoleApplication1\ConsoleApplication1\PVFProject1.lib(Lib.obj) 1
Error LNK1120 3 unresolved externals ConsoleApplication1 C:\Users\rt058861\Documents\Work\Tutorial_C++\tutorial13\ConsoleApplication1\x64\Debug\ConsoleApplication1.exe 1
I compiled the solution using Debug x64. No error occurs if I compile the static library using ifort, so I imagine that the problem is the linking between the library compiled using PGI fortran and the main program.
I also tried to compile and link the files using the PGI command windows and the pgcc compiler. The result is the following
pgf90 -c Lib.f90
pgcc Source.c Lib.obj
Source.c:
PGC-W-0156-Type not specified, ‘int’ assumed (Source.c: 7)
PGC/x86-64 Windows 17.9-0: compilation completed with warnings
Lib.obj : error LNK2001: unresolved external symbol ISO_C_BINDING
Lib.obj : error LNK2001: unresolved external symbol f90_compiled
Source.exe : fatal error LNK1120: 2 unresolved externals
Thank you for any help you can give me.
Regards
Riccardo