visual studio - C++ getting LNK2019 error, even though no circular dependency, and nothing included twice -


okay i'm trying create entity component system, , until been working pretty decent, i've encountered linker errors i'm not sure why, i've tried different variations hours can't work, know have made silly mistake can't find it, here files:(general nothing!, , haven't touched main, suppose linker errors caused entity , public files)

and have giant wrapper thats 'public.h' includes necessary headers, , has reusable methods, here public.h:

#pragma once #include <iostream> #include <vector> #include <string>  using namespace std; static int counter = 0; static int namcounter = 0; static int tagcounter = 0; static vector <string> allnames; static vector <string> alltags; //static vector <entity> allentities;  //static void addtoallent(entity* newe){ //}  int getcounter(); int getnamcounter(); int gettagcounter(); string uniquename(string un = "lol"); string uniquetag(string ut = "lol"); 

all fine, , here 'public.cpp':

#include "public.h"  //static void addtoallent(entity* newe){ //}  static int getcounter(){     return counter++; } static int getnamcounter(){     return tagcounter++; } static int gettagcounter(){     return namcounter++; } static string uniquename(string un){     if (un == "lol")         return "_entity" + to_string(getnamcounter());     (int = 0; < alltags.size(); i++){         if (alltags.at(i) == un)             return "_entity" + to_string(getnamcounter());     }     alltags.push_back(un);     return un; } static string uniquetag(string ut){     if (ut == "lol")         return "_entitytag" + to_string(gettagcounter());     (int = 0; < alltags.size(); i++){         if (alltags.at(i) == ut)             return "_entitytag" + to_string(gettagcounter());     }     alltags.push_back(ut);     return ut; } 

then problem lies in entity files, here entity.h:

#pragma once  class entity { private:     int id;     string name;     string tag;     //vector <component> allcomps; public:     friend bool operator==(const entity& left, const entity& right){         return ((left.name == right.name) && (left.tag == right.tag));     }     friend bool operator!=(const entity& left, const entity& right){         return !(left == right);     }     entity();     entity(const entity&);     entity(string);     entity(string, string);     ~entity();     int getid();     string getname();     string gettag();     void start();     void update();     void setall(string, string);     void printall(); }; 

and here entity.cpp:

#include "public.h" #include "entity.h"  entity::entity() {     id = getcounter();     this->name = uniquename();     this->tag = uniquetag(); } entity::entity(string name){     id = getcounter();     this->name = uniquename(name);     this->tag = uniquetag(); } entity::entity(string name, string tag){     id = getcounter();     this->name = uniquename(name);     this->tag = uniquetag(tag); }  int entity::getid(){ return this->id; } string entity::getname(){ return this->name; } string entity::gettag(){ return this->tag; } void entity::printall(){     cout << "name: \"" << this->name << "\" tag: \"" << this->tag << "\" id: \"" << this->id << "\"" << endl; } void entity::setall(string newn, string newt){     this->tag = newt;     this->name = newn; }  void entity::start(){  } void entity::update(){  }  entity::~entity() { } 

and causing me lot of linker errors, i'm not sure why, i'm pretty sure linked correctly, , nothing included twice etc, still theese errors:

error   1   error lnk2019: unresolved external symbol "int __cdecl getcounter(void)" (?getcounter@@yahxz) referenced in function "public: __thiscall entity::entity(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0entity@@qae@v?$basic_string@du?$char_traits@d@std@@v?$allocator@d@2@@std@@0@z)    c:\users\drin-_000\documents\visual studio 2013\projects\ecsystem\ecsystem\entity.obj   ecsystem error   2   error lnk2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl uniquename(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?uniquename@@ya?av?$basic_string@du?$char_traits@d@std@@v?$allocator@d@2@@std@@v12@@z) referenced in function "public: __thiscall entity::entity(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0entity@@qae@v?$basic_string@du?$char_traits@d@std@@v?$allocator@d@2@@std@@0@z)  c:\users\drin-_000\documents\visual studio 2013\projects\ecsystem\ecsystem\entity.obj   ecsystem error   3   error lnk2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl uniquetag(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?uniquetag@@ya?av?$basic_string@du?$char_traits@d@std@@v?$allocator@d@2@@std@@v12@@z) referenced in function "public: __thiscall entity::entity(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0entity@@qae@v?$basic_string@du?$char_traits@d@std@@v?$allocator@d@2@@std@@0@z)    c:\users\drin-_000\documents\visual studio 2013\projects\ecsystem\ecsystem\entity.obj   ecsystem error   4   error lnk1120: 3 unresolved externals   c:\users\drin-_000\documents\visual studio 2013\projects\ecsystem\debug\ecsystem.exe    ecsystem 

remove static implementation of getcounter, getnamcounter, gettagcounter, uniquename,uniquetag( functions in public.cpp - not meant static

[edit] other linkage errors.

also, in public.h, replace static extern in declaration of

extern int counter = 0; extern int namcounter = 0; extern int tagcounter = 0; extern vector <string> allnames; extern vector <string> alltags; 

and implement them in public.cpp

int counter = 0; int namcounter = 0; int tagcounter = 0; vector <string> allnames; vector <string> alltags; 

see extern here


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -