PGI Visual Fortran with Visual Studio 2010 C

I can’t get a very simple project to link in Visual Studio. I keep getting unresolved external symbol multiply referenced in function _main. What am I missing or doing wrong. I can supply the sample project if need be. Thanks.

simple.c

#include <stdio.h>

extern void multiply_();

int main(int argc, const char* argv[])
{
	double a = 2;
	double b = 2;
	double c = 0;

	multiply_(&a, &b, &c);
	
	printf("%f * %f = %f", a, b, c);

	return 0;
}

compile c project exe

/I"c:\Users\developer\Documents\Visual Studio 2010\Projects\RRT\cutils\" /ZI /nologo /W3 /WX- /Od /Oy- /D "_MBCS" /Gm /EHsc /RTC1 /MTd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fp"c:\Users\developer\Documents\Visual Studio 2010\Projects\RRT\prep_pfps_v30\Win32\Debug\prep_pfps_v30.pch" /Fa"c:\Users\developer\Documents\Visual Studio 2010\Projects\RRT\prep_pfps_v30\Win32\Debug\" /Fo"c:\Users\developer\Documents\Visual Studio 2010\Projects\RRT\prep_pfps_v30\Win32\Debug\" /Fd"c:\Users\developer\Documents\Visual Studio 2010\Projects\RRT\prep_pfps_v30\Win32\Debug\vc100.pdb" /Gd /analyze- /errorReport:queue

link c project exe

/OUT:"c:\Users\developer\Documents\Visual Studio 2010\Projects\RRT\Distribution\Win32\Debug\RRT\Programs\utils\prep_pfps_v30.exe" /NOLOGO /LIBPATH:"C:\Program Files\PGI\win32\11.3\lib\" /LIBPATH:"c:\Users\developer\Documents\Visual Studio 2010\Projects\RRT\Distribution\Win32\Debug\RRT\Programs\utils\" "futils.lib" "libpgmp.lib" "pg.lib" "libpgf90.lib" "libpgf90_rpm1.lib" "libpgf902.lib" "libpgf90rtl.lib" "libpgftnrtl.lib" "libpgc.lib" "libnspgc.lib" "libcmt.lib" /MANIFEST /ManifestFile:"c:\Users\developer\Documents\Visual Studio 2010\Projects\RRT\prep_pfps_v30\Win32\Debug\prep_pfps_v30.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"c:\Users\developer\Documents\Visual Studio 2010\Projects\RRT\Distribution\Win32\Debug\RRT\Programs\utils\prep_pfps_v30.pdb" /PGD:"c:\Users\developer\Documents\Visual Studio 2010\Projects\RRT\Distribution\Win32\Debug\RRT\Programs\utils\prep_pfps_v30.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE

futils.f

!--------------------------------MULTIPLY-------------------------------

       SUBROUTINE MULTIPLY (RA, RB RC)

       DOUBLE PRECISION RA, RB, RC

       RC = RA * RB

       RETURN
       END

compile static fortran library project

-g -Bstatic -Mbackslash -I"c:\program files\pgi\win32\11.3\include" -I"C:\Program Files\PGI\Microsoft Open Tools 10\include" -I"C:\Program Files\PGI\Microsoft Open Tools 10\PlatformSDK\include" -Minform=warn

link static fotran library project

/OUT:"c:\Users\developer\Documents\Visual Studio 2010\Projects\RRT\Distribution\Win32\Debug\RRT\Programs\utils\futils.lib"

Hi initialzero,

The easiest thing to do is compile the Fortran code with “-Miface=unix”.

PGI$ pgf90 -c  test_f.f90
PGI$ pgcc test_c.c test_f.obj -pgf90libs
test_c.obj : error LNK2019: unresolved external symbol _multiply_ referenced iifunction _main
test_c.exe : fatal error LNK1120: 1 unresolved externals
test_c.c:
PGI$ pgf90 -c -Miface=unix test_f.f90
PGI$ pgcc test_c.c test_f.obj -pgf90libs
test_c.c:
PGI$

For full details please refer to Chapter 12 of the PGI User’s Guide under the section titled “Win32 Calling Conventions” (http://www.pgroup.com/doc/pgiug.pdf)

Hope this helps,
Mat

I thought I was accounting for the underscore by using

extern void multiply_();

But -Miface=unix seems to be happier. Although, I now am getting:

error LNK2019: unresolved external symbol ___mth_i_dsinx referenced in function _ll2xy_
error LNK2019: unresolved external symbol ___mth_i_dcosx referenced in function _ll2xy_
error LNK2019: unresolved external symbol ___mth_i_dsincosx referenced in function _xy2ll_
error LNK2019: unresolved external symbol ___mth_i_dasinx referenced in function _xy2ll_
error LNK2019: unresolved external symbol ___mth_i_idnintx referenced in function _angnrm_
error LNK1120: 5 unresolved externals

Thanks for the help.

I thought I was accounting for the underscore by using

extern void multiply_();

This is the UNIX format. The default on Win32 is all upper case followed an at sign and the number of bytes in the argument list, for example “MULTIPLY@12”.

error LNK2019: unresolved external symbol ___mth_i_dsinx referenced in function ll2xy

These are the SSE versions of our intrinsics which are found in the “libpgsse2.lib” library. Please add this library as well as the “libpgsse1.lib” library to your link. Alternatively, remove the “-fastsse” flag from your compilation to not use SSE.

If possible, the easiest thing to do is link using the PGI Fortran driver adding “-Mnomain” if your main program is written in C. This way all the necessary libraries will be add automatically.

Hope this helps,
Mat

Just to note, I am using Microsoft Visual Studio 2010 C/C++ to link and I was not using the -fastsse switch. My main program using the library is in Microsoft C. By adding libpgsse1 and 2 I have successfully linked.

My linker’s additional dependencies are:

libpgsse1.lib;libpgsse2.lib;libpgc.lib;libpgmp.lib;pg.lib;libpgf90.lib;libpgf90_rpm1.lib;libpgf902.lib;libpgf90rtl.lib;libpgftnrtl.lib;libnspgc.lib;libcmt.lib;%(AdditionalDependencies)