Thread: Windows Link.exe error LNK2019 unresolved external symbol

  1. #1
    Registered User
    Join Date
    Sep 2019
    Posts
    12

    Windows Link.exe error LNK2019 unresolved external symbol

    I have an exe written in C to call a dll. It compiles with Clang and I'm linking it from the Visual Studio command line using link.exe. Link.exe gives me these errors:

    error LNK2019: unresolved external symbol __imp_LoadLibraryA referenced in function WinMain
    error LNK2019: unresolved external symbol __imp_GetProcAddress referenced in function WinMain
    error LNK2019: unresolved external symbol __imp_FreeLibrary referenced in function WinMain
    error LNK2019: unresolved external symbol __stdio_common_vsprintf referenced in function _vsnprintf_l
    unresolved external symbol WinMainCRTStartup

    These LNK2019 errors all relate to Windows API functions that are in Windows.h, and windows.h is in my header file.

    This is the header file (SxSv.h):

    Code:
    #ifndef DLLHANDLER_C_
    #define DLLHANDLER_C_
       
    #include <windows.h>
    #include <winbase.h>
    #include <windef.h>
    #include <stdio.h>
       
    typedef int (*TestFunc)(int);
       
    int loadDLL( void );
       
    #endif
    Code:
    This is the C file (SxSv.c) :
    
    #include "SxSv.h"
     
    int WinMain()
    {
      int status = 0;
      TestFunc _TestFunc;
      HINSTANCE testLibrary = LoadLibrary("SxSv.dll");
     
      if (testLibrary) {
        _TestFunc = (TestFunc) GetProcAddress(testLibrary, "SSXV");
        if (_TestFunc) {
          status = _TestFunc();
        }
     
        FreeLibrary(testLibrary);
     
      }
      return status;
    }
    The link string for Link.exe:

    link SxSv SxSv.obj

    I have an include for Windows.h specified in the header file, so what else do I need to reference?

    Thanks.
    Last edited by Cfan12; 09-15-2019 at 11:56 AM.

  2. #2
    Registered User
    Join Date
    Sep 2019
    Posts
    12
    Issue with code formatting: when I view this thread without logging in, I see the first section of this post shifted to the right by a large amount. When I view it logged in, that does not happen. I am trying to get the formatting right for this site. Why does that happen? This post was posted entirely from plain text per instructions from the site moderator yesterday.

  3. #3
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338
    Linker problems compiling as 64-bit

    I was able to solve this problem by adding the following line to the Additional Library Directories:
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\x64
    "without goto we would be wtf'd"

  4. #4
    Registered User
    Join Date
    Sep 2019
    Posts
    12
    Here is a screenshot with me logged in, which is followed by a screenshot of me logged out. You will notice how the top of the post shifts far to the right when I'm logged out. Thanks again.

    Windows Link.exe error LNK2019 unresolved external symbol-formatting-when-logged-jpg

    Logged out:

    Windows Link.exe error LNK2019 unresolved external symbol-formatting-when-logged-out-jpg

  5. #5
    Registered User
    Join Date
    Dec 2017
    Posts
    1,628
    When you are not logged in, an ad is shown in that location.
    Since you are using an ad-blocker, it appears as a blank space.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  6. #6
    Registered User
    Join Date
    Sep 2019
    Posts
    12
    I'll whitelist your site so the adblocker doesn't block the ad.

  7. #7
    Registered User
    Join Date
    Sep 2019
    Posts
    12
    To Structure: thanks for your reply. Mine is in a different location, but it didn't make any difference. Here's my string:

    l
    ink SxSv SxSv.obj /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64\" -- but I still get the same errors.

  8. #8
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338
    I still get the same errors.
    Take a look at this:
    Linker Tools Error LNK2019 | Microsoft Docs
    "without goto we would be wtf'd"

  9. #9
    Registered User
    Join Date
    Dec 2017
    Posts
    1,628
    It presumably needs to be something like this (all on one line):
    Code:
    link.exe
      /nologo
      /subsystem:windows
      /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64\"
      /out:SxSv.exe
      kernel32.lib
      SxSv.obj
    A little inaccuracy saves tons of explanation. - H.H. Munro

  10. #10
    Registered User
    Join Date
    Sep 2019
    Posts
    12
    Structure - that article at Microsoft looks very useful. Thanks for the link. I will study it.

    John C, it looks like we're getting somewhere. Your link string puts me in a better place. Here's what I get:

    LINK : warning LNK4001: no object files specified; libraries used
    LINK : warning LNK4068: /MACHINE not specified; defaulting to X86
    LINK : fatal error LNK1159: no output file specified

    Now I can specify /MACHINE and find out how link wants the output file specified (despite the out: directive on the command string, it wants something different).
    Last edited by Cfan12; 09-15-2019 at 05:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error LNK2019: unresolved external symbol
    By Cannibalope in forum C++ Programming
    Replies: 3
    Last Post: 12-06-2012, 09:35 PM
  2. error LNK2019: unresolved external symbol
    By kiros88 in forum C++ Programming
    Replies: 7
    Last Post: 06-16-2010, 01:16 PM
  3. Help with: error LNK2019: unresolved external symbol
    By darren78 in forum C++ Programming
    Replies: 2
    Last Post: 06-16-2010, 06:26 AM
  4. error LNK2019: unresolved external symbol
    By Warlax in forum C++ Programming
    Replies: 8
    Last Post: 12-09-2008, 01:37 PM
  5. error LNK2019: unresolved external symbol
    By Opel_Corsa in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2006, 12:12 PM

Tags for this Thread