Problem
This article documents 2 known compitability issues when using the C compiler in Visual Studio 2015
1, The C runtime has been re-structured into multiple (separate) libraries which can lead to 'unresolved external' errors when linking, eg:
error LNK2019: unresolved external symbol __acrt_iob_func referenced in function main
error LNK2019: unresolved external symbol __stdio_common_vfprintf referenced in function _vfprintf_l
2. printf/scanf routines are now generated in-line (i.e. they are no longer part of the standard runtime libraries).
This can lead to the error "printf already defined" if pre-Visual Studio 2015 C object code modules (containing calls to these functions) are to be linked with, eg:
msvcrt.lib(MSVCR110.dll) : error LNK2005: printf already defined
Resolution
1. Typically you would now need to link with ucrt.lib, vcruntime.lib and msvcrt.lib (instead of just msvcrt.lib used in earlier C compilers) for any C code compiled with Visual Studio 2015. Thus it is necessary to use the link and libs from Visual Studio 2015 (it is no longer possible to link with some older version of the C runtime - which is what is generally supplied with the Visual Cobol product).
2. If it is necessary to link in some C object code from an earlier Visual Studio C compiler (e.g. a 3rd party library) or another language .obj (e.g. COBOL) that contains calls to these external prinf/scanf routines, they can still be resolved by linking in the additional legacy_stdio_definitions.lib and legacy_stdio_wide_specifiers.lib that are supplied with Visual Studo 2015.
Summary
Changes in the C compiler in Visual Studio 2015 affect the way you link COBOL object code and C object code built with that version of Visual Studio in the same executable.
In this scenario, you must use the Microsoft link utility and the C runtime libraries directly from Visual Studio, rather than the Micro Focus cbllink utility, the Microsoft link utility and the libraries supplied with Visual COBOL. You might also need to specify some additional C runtime libraries – see the Microsoft documentation for more details.
Note that when using COBOL and C object code together, Micro Focus recommends you build and maintain the COBOL and C executables as separate projects and use import libraries and the Micro Focus C functions for calling COBOL (see “C functions for calling COBOL” in the product help) to resolve calls between them.
References
https://msdn.microsoft.com/en-us/library/bb531344.aspx
https://msdn.microsoft.com/en-us/library/abx4dbyh.aspx
#MFDS
#printfvfprintffprintfmainunresolvedexternalsymbollinkerrorfatal
#EnterpriseDeveloper
