0
votes

I have two files that are causing me a lot of grief: camAVTEx.h and camAVTEx.cpp. Here is the general setup for the two files:


//.h////////////////////////////////////////////////

/*
#includes to some other files
*/

class camera_avtcam_ex_t : public camera_t
{
public:
    camera_avtcam_ex_t();
    virtual ~camera_avtcam_ex_t();

private:
    //some members

public:
    //some methods

};

void GlobalShutdownVimbaSystem();

//.cpp/////////////////////////////////////////////

#include "StdAfx.h"
#include "camAVTEx.h"

//some other #includes

camera_avtcam_ex_t::camera_avtcam_ex_t()
{
}

//rest of the class' functions

void GlobalShutdownVimbaSystem()
{
    //implememtation
}

Then, in a file in a different directory, I do a #include to the exact location of the .h file and try to use the class:


//otherfile.cpp

#include "..\..\src\HardSupport\Camera.h"
//this is the base camera class (camera_t)

#include "..\..\src\HardControl\camAVTEx.h" 
//this is indeed where both the .h and .cpp files are located

void InitCam
{
    camera_t* maincam = new camera_avtcam_ex_t();
}

void OnExit()
{
    GlobalShutdownVimbaSystem();
}

When I compile, I get the following errors:

8>otherfile.obj : error LNK2001: unresolved external symbol "public: __cdecl camera_avtcam_ex_t::camera_avtcam_ex_t(void)" (??0camera_avtcam_ex_t@@QEAA@XZ)

8>otherfile.obj : error LNK2001: unresolved external symbol "void __cdecl GlobalShutdownVimbaSystem(void)" (?GlobalShutdownVimbaSystem@@YAXXZ)

8>....\bin\x64\Release\otherfile.exe : fatal error LNK1120: 2 unresolved externals

I cannot for the life of me figure out why it can't find the implementations for these two functions.

So I guess my question is fairly obvious: Why am I getting these errors and what do I need to change to fix them?

1
are you sure the file has access to the include files in your program? It could be a possibility your file can't find those includes/ - Syntactic Fructose
fairly obvious, but are you sure that camAVTEx.cpp is compiled and linked along your otherfile.cpp file ? What is your build system ? - Offirmo
@Need4Sleep I don't see how it couldn't have access - xcdemon05
It's because CamAVTex.o is not being linked into your executable. It's nothing to do with the #include files. - Roddy
@xcdemon05 - Isn't this the same question you asked in March??? - Roddy

1 Answers

0
votes

Whatever how you look at it, the error you have : unresolved external symbol "public: __cdecl camera_avtcam_ex_t::camera_avtcam_ex_t(void)" (??0camera_avtcam_ex_t@@QEAA@XZ) means that the compiler knows the symbol camera_avtcam_ex_t::camera_avtcam_ex_ (that's the class constructor) since he saw its declaration in the camAVTEx.h file but halas, it can't find (= resolve) the implementation of this symbol (in short, the code).

This usually happen because of several possible causes :

  • you didn't tell the compiler about the code (.cpp) you try to use so he doesn't know it. Try to add the file to your project.
  • you compile the missing code, but don't link with it. Check if you don't have two separated projects or try to add the lib to your project if it comes from a lib.
  • in some way, the compiled code does not match its definition (happens when mixing C and C++ or messing with namespaces) Check if you are not declaring contradicting enclosing namespaces.
  • (maybe other reasons I don't know ?)