error LNK2019 unresolved external symbol using pgcpp

I need to link my Fortran program with a library written in C and C++. First, I use Microsoft C compiler in Visual Studio 2005 to build the C library and link to Fortran program, No error. Results are as expected.

When I use pgcc and pgcpp to build my C library (pgf_clibrary.lib) and link it with Fortran I have a lot of errors:

error LNK2019: unresolved external symbol ___curr_eh_stack_entry referenced in function _SKR_Get_Weight_Array pgf_clibrary.lib
error LNK2019: unresolved external symbol ___eh_curr_region referenced in function _SKR_Get_Weight_Array
error LNK2019: unresolved external symbol ___nw__FUi referenced in function _SKR_Get_Weight_Array pgf_clibrary.lib
error LNK2001: unresolved external symbol ___nw__FUi pgf_clibrary.lib
error LNK2001: unresolved external symbol ___dl__FPv pgf_clibrary.lib
error LNK2001: unresolved external symbol ___vtbl__Q2_3std9type_info

I notice that only the code in C++ have errors, no error for code written in C
my fortran code is compiled using PGF Visual fortran version 9.0-1
my c compiler is pgcc, pgcpp version 9.0-1.
I use Win XP, visual studio 2005

Please help me get rid of these errors. Thanks

Giang Nong

Hi Giang Nong,

I think you’re just missing the C++ rumtime libraries. Try adding the flag “-pgcpplibs” to your Fortran link.

Hope this helps,
Mat

Hi Matt,

I call my first email step 1, here are my steps 2, 3 and 4

Step2
When I added -pgcpplibs I did not get the previous error (of step 1) but I got a new error:

fatal error LNK1104: cannot open file ‘libC.lib’

step 3
I search for libC.lib and found one:
C:\Program Files\Microsoft Visual Studio\VC98\LIB

I add this path for libC.lib and got ALL PREVIOUS errors of step 1 plus NEW errors:

old error of step 1
error LNK2019: unresolved external symbol ___dl__FPv referenced in function ___dt__26ComputePossibleScoresClassFv
error LNK2019: unresolved external symbol ___nw__FUi referenced in function _SKR_Get_Weight_Array
new errors (to name only a few):
error LNK2005: ___initstdio already defined in libC.lib(_file.obj) libcmt.lib(_file.obj)
error LNK2005: ___endstdio already defined in libC.lib(_file.obj) libcmt.lib(_file.obj)
error LNK2005: __iob already defined in libC.lib(_file.obj) libcmt.lib(_file.obj)
error LNK2005: __cflush already defined in libC.lib(_file.obj) libcmt.lib(timeset.obj)
error LNK2005: __timezone already defined in libC.lib(timeset.obj) libcmt.lib(timeset.obj)
LINK : warning LNK4098: defaultlib ‘libcmt’ conflicts with use of other libs

step 4
I remove libcmt.lib by using -nodefaultlib=libcmt.lib and get new errors

error LNK2019: unresolved external symbol ___iob_func referenced in function _SKR90
error LNK2019: unresolved external symbol __localtime64 referenced in function _HandleError@20 skr90gen.lib
LNK2001: unresolved external symbol ___security_cookie skr90gen.lib
All errors of step 1 come back in step 4 although I still retain -pgcpplibs

Note:
In step 3 I also found another path for libC.lib
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib
but using this path gives similar errors

Giang

Hi Giang,


It looks like there’s a slight configuration error on our part for the -pgcpplibs flag with pgf90. “libC” is the linux name for the C++ runtime. It should be “libcpp” on Windows.

To work around the issue, try linking with “pgcpp -pgf90libs”, or edit the file called “nativerc” in your bin directory from:

variable NORMALCPPLIB is hide default©;
to
variable NORMALCPPLIB is hide default(cpp);

Sorry for the confusion,
Mat

Thank you, Matt

When I change file file nativerc as you suggest it works. I notice that I have this file in both folders:
C:\Program Files\PGI\win32\8.0-1\bin
C:\Program Files\PGI\win32\9.0-1\bin

To determine which folder I am using I type:

C:\PGF_Clibrary\C_code\debug>pgcpp -V

pgcpp 9.0-1 32-bit target on Win32
Copyright 1989-2000, The Portland Group, Inc. All Rights Reserved.
Copyright 2000-2009, STMicroelectronics, Inc. All Rights Reserved.

based on this information I think that I am using version 9.0-1 and I change file nativerc in 9.0-1. It does not work, same error.
Then I change file nativerc in folder 8.0-1 and suddenly all errors are gone.

So I think the information given by pgcpp -V is misleading.
Giang

FYI, this configuration problem will be resolved in the 9.0-4 release.

  • Mat