The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Linker Error
Discuss Linker Error in the C Programming forum on Dev Shed. Linker Error C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 30th, 2002, 03:21 AM
|
|
Junior Member
|
|
Join Date: Oct 2002
Location: Ireland
Posts: 26
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
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.
|

October 30th, 2002, 08:15 AM
|
|
Contributing User
|
|
Join Date: Oct 2002
Location: Flint, MI
Posts: 328
Time spent in forums: 1 h 19 m 25 sec
Reputation Power: 11
|
|
|
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/
|

October 30th, 2002, 04:29 PM
|
|
Junior Member
|
|
Join Date: Oct 2002
Location: Ireland
Posts: 26
Time spent in forums: < 1 sec
Reputation 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?
|

October 30th, 2002, 05:14 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
|
Shouldn't
Tag_Path t = Tag_Path(vs);
be written as:
Tag_Path t = new Tag_Path(vs);
|

October 31st, 2002, 08:32 AM
|
|
Contributing User
|
|
Join Date: Oct 2002
Location: Flint, MI
Posts: 328
Time spent in forums: 1 h 19 m 25 sec
Reputation Power: 11
|
|
Quote: 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.
|

November 5th, 2002, 11:45 AM
|
|
Junior Member
|
|
Join Date: Oct 2002
Location: Ireland
Posts: 26
Time spent in forums: < 1 sec
Reputation 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...
|

November 6th, 2002, 04:43 PM
|
|
Junior Member
|
|
Join Date: Oct 2002
Location: Ireland
Posts: 26
Time spent in forums: < 1 sec
Reputation 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 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|