Problem compiling mixed PGI/Intel Visual Fortran solution

Hello,

I am trying to implement a PGI Visual Fortran project into a pre-existing solution made by another Intel Visual Fortran project. This PGI Visual Fortran project is a static library and for the moment consists of a single source file, cuda_library.f90, which reads as follows

module cuda_library

“some variables”

contains

" some subroutines"

end module cuda_library

This module is used by the other Intel Visual fortran Project (i.e., use cuda_library). After linking the library and ensuring that the directory containing the cuda_library.mod file has been added to the include directories of the Inter Visual Fortran project, I tryed to compile the entire solution and I get the following error:

“error #7013: This module was not generated by any release of this compiler [cuda_library]”

The active configuration is Debugging, x64.

Thank you very much for any help.

Riccardo

Riccardo,

You cannot mix Fortran 90 objects and modfiles between two different
compilers. At best you can link fortran 77 objects from PGI with
Intel object files, but modfiles and other internally handled features
(like file logical unit numbers) are not handled in a way other
compilers can access and use.

Runtime libs between the compilers are incompatible as well.

But sometimes things work. So people think it should always
work.

dave

Dear Dave

Thank you very much for your help. So even if I pack all my CUDA Fortran subroutines into a dll, that is called eventually by an executable created using Intel Fortran, that would generate, in general, an incompatibility issue?

Apart from moving the existing Intel Fortran project to a PGI Fortran one, do you know a different approach that could solve my issue and at the same time preserve an eterogeneous (Intel and PGI) solution?

Regards

Riccardo

It is a basic issue of passing the intended arguments to the routines
to run them, and get the results back when done.

Fortran is like C++ in that the symbols are modified in the object file.
This does not happen with C code.

I would first attempt to call Cuda programs compiled with pgfortran
from a C program compiled with pgcc. Once that works, I would
then compile the C program with icc and make that work.

Once that works, I would call the C program compiled with icc or gcc from the program compiled with ifort, probably using the methodology of ISO_C_BINDING for the common C interface.

dave

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

Hello to everybody,

I managed to solve my problem and now the interface works. Basically, I created a mask into a separate PGI project that calls the main program as a subroutine

! Project 1-PGI Visual Fortran Console application

program cuda_mask
implicit none

interface
subroutine main_program() bind(C)
use, intrinsic :: ISO_C_BINDING
end subroutine
end interface

call main_program()
end program cuda_mask


! Project 2 - Intel Fortran Static Library
#include <stdio.h>

void pythagoras(float a, float b, float *c);

void main_program()
{
float c;
pythagoras(30, 40, &c);
printf(“Hypotenuse if sides 30, 40 is: %f\n”, c);
}

!Project 3 - PGI Fortran static library

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)
end subroutine pythagoras

After linking all the the projects together and compiling

1>------ Rebuild All started: Project: Library, Configuration: Debug x64 ------
1>Deleting intermediate and output files for project ‘Library’, configuration ‘Debug’
1>Compiling Project …
1>cuda_library.f90
1>Creating Library…
1>Library build succeeded.
1>
1>Build log was saved at “file://C:\Users\rt058861\Documents\Work\CUDAFortran\Working_interface\Library\x64\Debug\BuildLog.htm”
1>
2>------ Rebuild All started: Project: Main_program, Configuration: Debug x64 ------
2> Main_program.c
2> Main_program.vcxproj → C:\Users\rt058861\Documents\Work\CUDAFortran\Working_interface\x64\Debug\Main_program.lib
3>------ Rebuild All started: Project: Cuda_mask, Configuration: Debug x64 ------
3>Deleting intermediate and output files for project ‘Cuda_mask’, configuration ‘Debug’
3>Compiling Project …
3>cuda_mask.f90
3>Linking…
3>Main_program.lib(Main_program.obj) : warning LNK4075: ignoring ‘/EDITANDCONTINUE’ due to ‘/OPT:LBR’ specification
3>LINK : warning LNK4098: defaultlib ‘MSVCRTD’ conflicts with use of other libs; use /NODEFAULTLIB:library
3>Main_program.lib(Main_program.obj) : warning LNK4217: locally defined symbol __acrt_iob_func imported in function printf
3>Main_program.lib(Main_program.obj) : warning LNK4217: locally defined symbol __stdio_common_vfprintf imported in function _vfprintf_l
3>Cuda_mask build succeeded.
3>
3>Build log was saved at “file://C:\Users\rt058861\Documents\Work\CUDAFortran\Working_interface\Working_interface\x64\Debug\BuildLog.htm”
3>
========== Rebuild All: 3 succeeded, 0 failed, 0 skipped ==========

and runs successfully.

Thank you.

Riccardo