none
Link error after upgrade to MSVC 2017 RRS feed

  • Question

  • Hi, ALL,

    I'm having the same issue as described here, but for MSVC 2017.

    I tried to add the header files mentioned in the replies, but it didn't fix the problem.

    I also tried to follow the link to fix the odbccp32 but the link is dead.

    I would like the code to be compatible with MSVC 2010 and earlier, but it looks like I don't have a possibility to do so. (I'm working from MSVC IDE, not a command line compilation).

    Any idea on how to work around this?

    Thank you.

    Friday, August 3, 2018 4:10 PM

All replies

  • Did you added the required library file as well to your solution either by using Additinal Dependencies from project properties of by using #Pragma comment("lib"," lib Path") .

    Regarding compatibility 2017 will give you backward compatibility but if something is there which work in 2010 and not in 2017 or either way in that case you have to add conditional compilation in your code #ifdef etc.So it's doable but do you really want spend so much time in figuring all of this . if this is a small solution then it make sense else will not suggest you to go with this routine.

    Thanks


    Rupesh Shukla




    Friday, August 3, 2018 4:12 PM
  • Hi, Pintu,

    [quote]

    Did you added the required library file as well to your solution either by using Additinal Dependencies from project properties of by using #Pragma comment("lib"," lib Path") .

    [/quote]

    Which library you are talking about? According to the link in my OP, all I have to do is to include those files and that's it. Or in MSVC 2017 there is more to it?

    [quote]

    Regarding compatibility 2017 will give you backward compatibility but if something is there which work in 2010 and not in 2017 or either way in that case you have to add conditional compilation in your code #ifdef etc.So it's doable but do you really want spend so much time in figuring all of this . if this is a small solution then it make sense else will not suggest you to go with this routine.

    [/quote]

    In terms of backward compatibility and old version support - let me be the judge. I want to support "2010 and earlier versions".

    Now here is my code effort to do just that:

    [code]

    #if _MSC_VER >= 1900
    #include <cstdio>
    #include <cstdarg>
    #endif

    #ifdef WIN32
    #include <windows.h>
    #endif
    #ifndef WIN32
    #include <sstream>
    #endif

    #if defined __WXMSW__ && defined __MEMORYLEAKS__
    #include <vld.h>
    #endif

    #include <map>
    #include <set>
    #include <vector>
    #include <string>
    #include <algorithm>
    #include <sstream>
    #ifdef _IODBCUNIX_FRAMEWORK
    #include "iODBC/sql.h"
    #include "iODBC/sqlext.h"
    #include "iODBCinst/odbcinst.h"
    #else
    #include <sql.h>
    #include <sqlext.h>
    #include <odbcinst.h>
    #endif

    [/code]

    As you can see I did add the appropriate headers and still receive the error.

    Thank you.

    Friday, August 3, 2018 4:33 PM
  • regarding Compatibility :-

    First thing just adding header will not help you. You need to take care of corresponding library files as well. linker will use those file to link the library. So in 2010 and 2017 if they are different then you have to use it in appropriate manner. in last but not least even function signature if they are different then also you have to use different function in different version of compiler.

     Now linker error:- Two very common root cause for lnkerror are name mangling (extern "C" __stdcall).or missing function definition  . For function def we add corresponding header and library file. If both of these things are present then chances of getting link error is very low.

    Try above suggestion and if still you are getting error, post error message.

    Thanks


    Rupesh Shukla

    Friday, August 3, 2018 4:50 PM
  • Pintu,

    Did you read the reply I sent? And did you also try and read the issue I linked in my original posting?

    If you don't - please do so.

    If after doing that you are still confused, let me spell the problem for you nice and clearly.

    [quote]

    Hi,
    I recently upgraded my compiler/IDE to MSVC 2017 and now started getting a link error as such:

    Code:

    odbccp32.lib(dllload.obj) : error LNK2019: unresolved external symbol __vsnwprintf_s referenced in function _StringCchPrintfW

    Googling revealed that MS changed the function __vsnwprintf_s() to be inline and I should either link to some library (legacy_stdio_definitions.lib) or include the appropriate header. Both solutions are described here.

    I did it the second way, adding to one of the .cpp files:

    Code:

    #if _MSC_VER >= 1900
    #include <stdio.h>
    #include <stdarg.h>
    #endif

    but the error still there.

    Should I still link in the library, or just include that piece of code in every single source code file? The code is in DLL which contains just 2 cpp files - one to initialize the DLL and for the exported class definition.

    Or there is something else I should do?

    Thank you.

    [/code]

    I do hope that you are not lazy and will do what I suggested in my first 2 sentences. If not - just check the problem description above.

    Thank you.

    P.S.: I have been a developer a long time and explaining very basic thing to me is not helpful, but confusing. Please suggest a real solution on how to fix aforementioned error.

    Friday, August 3, 2018 5:02 PM
  • Including headers doesn't mean a thing here. Unless there is a #pragma comment(lib, "library") in the header file, it doesn't resolve the linker dependency.

    The cause of this is that when Visual Studio switched over to using the UCRT, functions like printf/fprintf and all supporting functions were made inline. This means that the ucrt import library doesn't resolve any of the printf family of functions.

    The odbc library is a static library, and it uses these functions, so including the headers will not resolve the symbols in the compiled static library.

    But the resolution of this is documented in the Visual C++ change history. There are two possible ways to solve this. First, use the versions of these odbc libraries in the Windows 10 SDK. The odbc components are built using the UCRT, so it will use the inline versions of these functions.

    Before you come up with the statement of "but the Windows 10 SDK means that I have to run it on Windows 10", no. The alternate SDK that you use is the Windows 8.1 SDK (unless you are building using the XP toolset) and this doesn't lock you into Windows 8.1. The desktop headers and libraries are officially supported to target Windows 7 SP1 and newer (unofficially you can probably get back to Vista).

    Second, if you are using the XP toolset, or just will not use the Windows 10 SDK, then Visual Studio 2017 includes the legacy_stdio_definitions.lib static library. This gives out of line definitions for the printf family of functions. So add this to your linker input, or in one of your source files add #pragma comment(lib, "legacy_stdio_definitions.lib") somewhere.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    • Proposed as answer by oneeyeman1 Saturday, August 4, 2018 3:36 AM
    Friday, August 3, 2018 5:07 PM
  • Interestingly, my post was flagged as spam. I noticed a typo and went to fix it.

    I guess me pointing out that you couldn't fix these linker errors by only including headers was offensive to someone. :)


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.


    Friday, August 3, 2018 5:16 PM
  • Hi, Darran,

    So basically all I need to do is:

    [code]

    #if _MSC_VER >= 1900

    #pragma comment(lib, "legacy_stdio_definitions.lib")

    #endif

    [/code]

    and I don't need to include anything.

    Then I will be able to build with any MSVC version.

    Is it correct?

    Thank you.

    Friday, August 3, 2018 5:30 PM
  • Darran,

    FWIW, it was not me who marked it. ;-)

    Thank you.

    Friday, August 3, 2018 5:31 PM
  • Yes, that's right.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Friday, August 3, 2018 5:43 PM
  • Pintu,

    Did you read the reply I sent? And did you also try and read the issue I linked in my original posting?


    You are not ready to listen, So i can't say much apart from Good luck. 

    Thanks


    Rupesh Shukla


    Friday, August 3, 2018 6:22 PM