How to read the Link Error message?  
Author Message
daniel mark





PostPosted: Visual C++ Language, How to read the Link Error message? Top

Hello all:

I find it is quite hard to understand the Link Error(I use VS. Net 2005 Professional).

If I include the following operator member function in the file "Triangle.cpp" rather than
in the file "Triangle.h".

inline bool Triangle::operator==(const Triangle &rhs) const
{
return (_length == rhs._length) && (_begin_pos == rhs._begin_pos);
}

Then call it by using the following statements:
Triangle t4(1, 2); // initialize _length as 1 and _begin_pos as 2
Triangle t5(1, 2);

if (t4 == t5)
cout << "equal " << endl;
else
cout << "not equal " << endl;

I will get the following build errors:
------ Build started: Project: TestOne, Configuration: Debug Win32 ------
Compiling...
TestOne.cpp
Linking...

D:\ALL_IN_ONE\Debug\TestOne.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://d:\ALL_IN_ONE\TestOne\Debug\BuildLog.htm"
TestOne - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


To me, this above build error message makes no sense at all.

Is there a way that could help me understand the real meaning under this LINK ERROR
So that I can get useful code information from the LINK ERROR messages.


Thank you very much!
-Daniel


Visual C++3  
 
 
Marius Bancila





PostPosted: Visual C++ Language, How to read the Link Error message? Top

Please post your actual code here. The following compiles fine for me:

class Triangle 
{
	int _length;
	int _begin_pos;
public:
	Triangle(int len = 0, int pos = 0):_length(len), _begin_pos(pos){}

	inline bool operator==(const Triangle& rhs) const ;
};

inline bool Triangle::operator==(const Triangle& rhs) const 
{
	return _length == rhs._length && _begin_pos == rhs._begin_pos;
}

int _tmain(int argc, _TCHAR* argv[])
{
	Triangle t4(1, 2); // initialize _length as 1 and _begin_pos as 2
	Triangle t5(1, 2);

	if (t4 == t5)
		std::cout << "equal " << std::endl;
	else
		std::cout << "not equal " << std::endl;

	return 0;
}



 
 
Viorel.





PostPosted: Visual C++ Language, How to read the Link Error message? Top

If you put your operator in a separate CPP file, then I think you have to remove inline from definition:

inline bool Triangle::operator==(const Triangle &rhs) const

{

    . . .

}

I hope it helps.

 


 
 
einaros





PostPosted: Visual C++ Language, How to read the Link Error message? Top

If you put your operator in a separate CPP file, then I think you have to remove inline from definition

Viorel, could you send a mail to the address in my profile



 
 
einaros





PostPosted: Visual C++ Language, How to read the Link Error message? Top

 
Hello all:

To me, this above build error message makes no sense at all.

Is there a way that could help me understand the real meaning under this LINK ERROR
So that I can get useful code information from the LINK ERROR messages.

The scrambled looking chunk of that error message is  the decorated name (think of it as a coded signature) of the function listed on the same line. Undecoration of such names, when found outside of the error message, can be done by use of the "undname" command line utility:

C:\Program files\Microsoft Visual Studio 8\VC>undname
Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation. All rights reserved.

Undecoration of :- " "
is :- "public: bool __thiscall Triangle::operator==(class Triangle const &)const"



 
 
daniel mark





PostPosted: Visual C++ Language, How to read the Link Error message? Top

This is the source code I used.

// TestOne.cpp -- the main program
#include <iostream>
#include "Triangle.h"
using namespace std;
int main(void)
{
Triangle t4(1, 2);
Triangle t5(1, 2);

if (t4 == t5)
cout << "equal " << endl;
else
cout << "not equal " << endl;
return 0;
}

// Triangle.cpp
#include "Triangle.h"
inline bool Triangle::operator==(const Triangle &rhs) const
{
return (_length == rhs._length) && (_begin_pos == rhs._begin_pos);
}

// Triangle.h
#pragma once

class Triangle
{
public:
Triangle(int length=0, int begin_pos=-1) : _length(length), _begin_pos(begin_pos){};
Triangle& copy(const Triangle&);
int getLength() const { return _length; }
int getBeginPos() const { return _begin_pos; }
bool operator==(const Triangle&) const;
public:
~Triangle(void) {};
public:
int _length;
int _begin_pos;
};

The build error is as follows:
------ Build started: Project: TestOne, Configuration: Debug Win32 ------
Compiling...
Triangle.cpp
Linking...

C:\tempp\TestOne\Debug\TestOne.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\tempp\TestOne\Debug\BuildLog.htm"
TestOne - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Thank you again)

 
 
Simple Samples





PostPosted: Visual C++ Language, How to read the Link Error message? Top

I often copy error messages such as that to a work area and then split and combine the text in whatever ways seem relevant and useful. So you might have something such as:

)

Note the double-quotes around the second line I have; they are a relevant delimiter for that line.

So do you have a body for Triangle::operator==(class Triangle const &)const



 
 
Damien Watkins - MSFT





PostPosted: Visual C++ Language, How to read the Link Error message? Top

Hello

Re: How to read the Link Error message

I am going to mark this thread as answered since you have not followed up with any further information on your problem as requested - I assume you solved the problem yourself or one of the suggestions in this thread helped you solved the problem. If you have a solution you could post it so others can find it. If you do not have a solution then please submit further details and then mark the thread as unanswered.

Thanks

Damien