How to handle the error "LNK2019 unresolved external symbol" in visual studio 2022

Blaise Xiangyun Deng 20 Reputation points
2023-07-09T08:28:29.6633333+00:00

ERROR CODE

The code is from Chapter 12, Programming Solving with C++, Tenth Edition, a programming example given by the author. I am not sure if I have done something wrong with Visual Studio settings.

Background: I'm using VS code with Visual Studio 2022

To help me resolve this issue, could you please guide me on what could be the potential causes of this error and how to fix it? Thank you.

Developer technologies | C++
{count} votes

Accepted answer
  1. Minxin Yu 13,506 Reputation points Microsoft External Staff
    2023-07-10T05:41:08.2733333+00:00

    Hi, @Blaise Xiangyun Deng

    The code works fine in Visual Studio. (Remove #include <dtime.cpp> in the last line of 12-08.cpp)

    Create an empty project and add .h/.cpp files to the project.
    User's image

    enter image description here

    Since your error is generated in Visual Studio Code (which is different from Visual Studio). Please try to compile your code in Visual Studio. (Do not forget to install C++ workload in Visual Studio Installer)
    For problems about Visual Studio Code, you could ask for help on GitHub.

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. RLWA32 49,636 Reputation points
    2023-07-09T13:12:55.56+00:00

    The linker error messages indicate that the linker has not been provided the implementation of the DigitalTime class.

    It appears from the image posted that the source file dtime.cpp has not been compiled (I assume that is the implementation). If it has, perhaps the resultant dtime.obj file has not been specified as a linker input.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.