Unresolved external symbol error when using multiple directories with c++ project

jjs 1 Reputation point

Hello, I'm having an issue where VS is throwing an unresolved external symbol error and I'm not sure how to resolve this.

Error: LNK2019 unresolved external symbol "public: __thiscall coppercable::coppercable(void)" (??0coppercable@@QAE@XZ) referenced in function _main NetworkStackMain C:\Users\JoshS\OneDrive\NetworkStack\NetworkStack\NetworkStackMain\NetworkStackMain.obj 1

After a few searches this seems to commonly be due to the linker being unable to find this function declaration. I attempted to add the directories of the file containing the function the error is referring to, coppercable::coppercable(), but this did not help.

Here is the location of my VS project files, per the error


And here is the location of the file containing the function declaration, note the definition is in a cpp file in /source instead of /header


Code in main:

#include <iostream>  
#include "cable.hpp"  
#include "coppercable.hpp"  

using namespace std;  

int main()  
    cable* cable1 = new coppercable();  
    cout << cable1->getAwgRating();  

Header file with function declaration:

#include <iostream>  
using namespace std;  

class coppercable : public cable  
        double getPowerLoss() override;  

Source file with function definition:

#include "../header/coppercable.hpp"  
#include "../header/copperwire.hpp"  
#include <iostream>  
#include <math.h>  
using namespace std;  



And for project properties, I've tried adding multiple directories including the exact directory where the source and header files are which contain the functions declaration/definition


Has anyone experienced this kind of issue based on this scenario? Any pointers or ideas is appreciated, thank you!

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.
2,903 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
773 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 95,076 Reputation points

    Probably you must add coppercable.cpp and maybe other .cpp files to your project. Right-click Source Files or project node in Solution Explorer, go to Add, Existing Item and select the file.

    The longer way: create a Static Library or DLL, which can be used in many main projects.

    0 comments No comments

  2. Dylan Zhu-MSFT 6,381 Reputation points

    Hi jjs,

    The LNK2019 often means that your declaration is not defined. You can try to add the directories of source files in VC++ Directories/Source Directories.
    Best Regards,

    If the answer is helpful, please click "Accept Answer" and upvote it.
    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