Thread: Linker Error

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Ireland
    Posts
    26
    Rep Power
    0

    Question Linker Error


    I recieve this error :
    [Linker error] undefined reference to `Tag_Path::Tag_Path(vector<basic_string<char, string_char_traits<char>, __default_alloc_template<false, 0> >, allocator<basic_string<char, string_char_traits<char>, __default_alloc_template<false, 0> > > >)'

    when I try to compile my code. Im sure there is some very simple explanation for it but I have tried everything I can think of. Im not sure if Im allowed to post my code but I dont know how else anyone can help me. And the length of the code is fairly short.

    Firstly I have a tester class Tag_Path_Tester:
    int main()
    {
    cout << "Creating vector of strings vs \n";
    vector<string> vs(5);
    vs[0] = "zero";
    vs[1] = "one";
    vs[2] = "two";
    vs[3] = "three";
    vs[4] = "four";
    cout << "Creating a Tag_Path variable t /n";
    Tag_Path t = Tag_Path(vs);
    /*cout << "Tag Path contents \n";
    for (int i=0; i<(t.get_path()).size(); i++)
    {
    cout << (t.get_path())[i];
    }

    /*wait*/int x;
    cin >> x;
    }
    As one can see that uses my own class Tag_Path which follows. The Header file, and then the other

    Header :
    class Tag_Path
    {
    public:

    Tag_Path(vector<string> paths);
    void add_road(string road);
    void remove_top_element();
    string get_top_element() const;
    vector<string> get_path() const;

    private:
    vector<string> roads;
    };
    Implementation
    Tag_Path::Tag_Path(vector<string> paths)
    {
    roads = paths;
    }


    void Tag_Path::add_road(string road)
    {
    roads.push_back(road);
    }

    void Tag_Path::remove_top_element()
    {
    roads.pop_back();
    }

    string Tag_Path::get_top_element() const
    {
    return roads[roads.size()-1];
    }

    vector<string> Tag_Path::get_path() const
    {
    return roads;
    }

    N.B. Im using Dev-C 4.9.6.0 as my compiler and I left out things like using namespace std and the #includes to try reduce the code length.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    12
    The problem probably has to do with including the implementation object into the project for the executable. I don't know the specifics of your development environment, but typos and missing object files are the most likely problems.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development
    http://www.lazarusid.com/notes/
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Ireland
    Posts
    26
    Rep Power
    0
    Thanks for your input thus far. While there could be typos I dont seem to see them , and you obviously didnt either.
    The includes i have for the files are as follows:
    Tag_Path_Test.cpp:
    #include <iostream>
    #include <string>
    #include <vector>
    #include <Tag_Path.h>

    Tag_Path.cpp:
    #include <Tag_Path.h>

    Tag_Path.h:
    #include <vector>
    #include <string>

    It really is a very basic class.
    There is one other thing of note
    I get an error when I try to compile Tag_Path.cpp
    Winmain@'16
    maybe this free compiler I have is not so good. You get nothing for nothing in this world I guess?
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,624
    Rep Power
    4247
    Shouldn't
    Tag_Path t = Tag_Path(vs);
    be written as:
    Tag_Path t = new Tag_Path(vs);
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    12
    Originally posted by gamgee
    There is one other thing of note
    I get an error when I try to compile Tag_Path.cpp
    Winmain@'16
    maybe this free compiler I have is not so good. You get nothing for nothing in this world I guess?
    Don't knock the free compilers. The GNU compilers are free and very excellent quality. Cygwin Distribution from Redhat is probably the easiest to install.

    The error message is very indicative of your problem. First, if Tag_Path.cpp is a class implementation, it definitely shouldn't have a Winmain function. Second, it's failure to compile would lead directly to a linking error in any module which uses the Tag_Path library implementation.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development
    http://www.lazarusid.com/notes/
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Ireland
    Posts
    26
    Rep Power
    0

    still have problems.....


    Can someone please tell me quickly....
    ...is it correct to have a parameter of type <vector> string in a constructor. Some told me to change 'em for char * but Im not so sure...
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Ireland
    Posts
    26
    Rep Power
    0

    Cheers


    Id like to just thank anyone who replied to my posting or even botherd to look at it. I have solved the problem, and I guess I should be feeling a little foolish right now. I was trying to compile the three files individually. They were not part of a project. once I created a project and added them to it, complied perfectly:p

IMN logo majestic logo threadwatch logo seochat tools logo