Missing symbols: _environ, _filbuf, _filsbuf

Trying to link a pgf95 compiled module (using v18.7) with a Visutal Studio 2015 C++ project. Currently linking with the following PGI static libraries ( to avoid redistributing .dll’s):


Added the following definition to resolve _iob_func:

extern "C" { FILE _iob[3] = { __acrt_iob_func(0), __acrt_iob_func(1), __acrt_iob_func(2) }; }
extern "C" FILE * __cdecl __iob_func(void)
	return _iob;

Does anybody have a similar remedy for the following unresolved symbols:

libpgc.lib(pgstdinit.obj) : error LNK2001: unresolved external symbol _environ
libpgc.lib(pgstdinit.obj) : error LNK2001: unresolved external symbol _filbuf
libpgc.lib(pgstdinit.obj) : error LNK2001: unresolved external symbol _flsbuf

Hi David,

These look like these symbols found in the Microsoft C Static runtime libraries (libcmt.lib, libcrt.lib). Are you linking with the “-Bstatic” flag? This flag will have the linker use the PGI static runtime libraries as well as libcmt.lib/libcrt.lib.

If you’re manually linking, you can use the linker flags “-nodefaultlib:msvcrt -defaultlib:libvcruntime -defaultlib:libucrt -defaultlib:libcmt” to use the MS static runtime.

Hope this helps,

Hi Mat,

Thanks for posting a reply. To answer your questions:

  • I am only compiling the Fortran object file using pgf95. Here’s the nmake file to do the Fortran compiling:

COMPILE    = pgf95 -fastsse -c

..\..\pc_ntcs\radcal\radcal_dist\mdl_radcal_dist.obj: mdl_radcal.f
	$(COMPILE) mdl_radcal.f -o ..\..\pc_ntcs\radcal\radcal_dist\mdl_radcal_dist.obj

(i.e., -Bstatic not required)

  • The above ‘mdl_radcal_dist.obj’ is linked with a much larger C/C++ project which uses the Visual Studio ‘Multi-threaded DLL (/MD)’ Runtime library. This has not prevented us from linking with the static versions of the PGF libraries (listed in my original post) until we tried to migrate up to Visual Studio 2015. Something changed in the Visual Studio 2015 version of the run-time libraries – they no longer use the variables listed

I did find a proposed work around (legacy_stdio_definitions.lib):
but this does not seem to work for _environ, _filbuf, and _filsbuf.

FYI: I took the last VS 2015 compatible version of PGI fortran (PGI Workstation 18.7). At present, we have reverted back to VS 2013 (using PGI Workstation 17.10).

Hi David,

It’s unclear why it works with VS2013. The PGI static runtime libraries are only expected to be used when linking staticly with the MS static C runtime libraries (libcmt.lib, libcrt.lib). When linking a project compiled with “/MD”, the PGI dynamic runtime libraries should be used so the VS2015 behavior is what I would expect.