0

So I've read most post down here regarding this error, I'm still unable to understand the cause of my error. The project consists of 2 header files along with cpp implementations + main cpp file.

DbApi.h contains definitions for functions implemented in DbApi.cpp. Linker.h contains definitions for functions called by Source.cpp, while Linker.cpp contains their implementations, which are calling functions from DbApi.h

Linker.h

#ifndef LINKER_DEFINED
#define LINKER_DEFINED

#include "DbAPI.h"

enum Short_Result_Code{...};

Short_Result_Code createNewCategory(string name, list <int>  &Parents);

#endif

Linker.cpp

#include "Linker.h"

Short_Result_Code createNewCategory(string name, list <int> &Parents)
{
int RC = db::addCategory(name, Parents);
if(RC==0)
    return OK;
else
    return ERROR;
}

DbApi.h

#ifndef __dbAPI_H_INCLUDED
#define __dbAPI_H_INCLUDED


namespace db
{
int addCategory(string name, list <int> parents);
}
#endif

DbApi.cpp

#include "DbAPI.h"

namespace db
{
    int addCategory(string name, list <int> parents)
 {
         // implementation
 };
 }

main.cpp

#include "Linker.h"

int main
{
    list<int> A;
A.push_back(1);
A.push_back(2);
string d = "ABC";
createNewCategory(d, A);
}
  • error:

    error LNK2019: unresolved external symbol "enum Short_Result_Code __cdecl createNewCategory(class std::basic_string,class std::allocator >,class std::list > &)" (?createNewCategory@@YA?AW4Short_Result_Code@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$list@HV?$allocator@H@std@@@3@@Z) referenced in function _main F:\AeroFS\Work\ETI\PDFAccess\PDFAccess\Source.obj PDFAccess

Where am I getting this wrong?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Ghostli
  • 383
  • 1
  • 3
  • 11
  • What development system are you using? make, SCONS, Visual Studio... – Ed Heal Nov 03 '13 at 11:11
  • 3
    Shall we assume you properly include all the appropriate standard library headers in the *real* code that replicates the *real* issue, rather than this? – WhozCraig Nov 03 '13 at 11:11
  • 1
    Linker.cpp isn't getting compiled – Luchian Grigore Nov 03 '13 at 11:18
  • You're missing the `#endif` at the end of each header. Check also that you really have matching braces in all your headers. – Alan Stokes Nov 03 '13 at 11:23
  • VS2012, #endif is included. I pasted this snippet so it would be more readable. Other includes are only STL standard libraries, so they cannot cause this error. I strongly suppose that the structure of includes is incorrect, yet dont know why. – Ghostli Nov 03 '13 at 11:32
  • This isn't the problem, but names that contain two consecutive underscores (`__dbAPI_H_INCLUDED`) and names that begin with an underscore followed by a capital letter are reserved to the implementation. Don't use them. – Pete Becker Nov 03 '13 at 13:49

1 Answers1

1

It looks like object file of Linker.cpp was not included in the project

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335