How to fix LNK2019 error

Keitel 61 Reputation points
2024-04-16T21:05:50.7266667+00:00

I have a desktop program in C that was formerly compiled in Visual Express some years ago, and it worked fine. Then I updated to Visual Studio 2022 to do some minor changes in the source code, and now I get the error LNK2019 and LNK2020.

Error LNK2019 unresolved external symbol __imp__PathCchRemoveFileSpec@8 referenced in function _WndProc@16

Error LNK2019 unresolved external symbol __imp__PathCchAppend@12 referenced in function _WndProc@16

I have been googling and tried out many different suggestions, but nothing works. I am quite at a loss, because I have difficulty in understanding what this error is about, while I am also hoping for an easy way out. Help would be greatly appreciated.

Thanks in advance.

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,630 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,613 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,530 questions
{count} votes

Accepted answer
  1. Michael Taylor 48,311 Reputation points
    2024-04-16T21:22:41.5433333+00:00

    The error itself says that somewhere in your code you are using PathCchRemoveFileSpec (or whatever). The compiler was able to find the function signature so it knew what arguments to expect and what data it returned. This is what header files provide so it got past the compiler.

    However eventually the actual implementation needs to be brought in to make the program complete. This is where libraries (.obj, .lib, .dll) come in. They provide the actual implementation and that is what the linker is looking for. When it cannot find the implementation of a function that you are calling then you get this error.

    If the function is in your code somewhere then the .obj produced during the build contains it. If it is library code provided by someone else then you'll get a .lib file instead. That ships with the library in question. If the library is a static library then all the code is in the .lib and it is merged into your code by the linker. However if it is a dynamic library then the .lib only contains the necessary code to link it to the DLL that your code is going to rely on at runtime. This is the most common case for things like operating system files.

    With that out of the way, a quick google for the function in question goes to here. In the Requirements section it indicates the header file you need to include to make the compiler happy and the library file you need to link with to make the linker happy. In your Linker settings should be a list of libraries you depend on (kernel32, user32, etc). Ensure that pathcch.lib is part of that list. Assuming you have your system configured with the necessary SDKs then it should find the library as part of the linker search process.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful