8 Replies - 3234 Views - Last Post: 07 August 2012 - 11:10 AM Rate Topic: -----

#1 WabiSabi  Icon User is offline

  • D.I.C Head

Reputation: 51
  • View blog
  • Posts: 202
  • Joined: 31-December 10

error LNK2019: unresolved external symbol

Posted 03 August 2012 - 05:17 AM

What does this error mean? Or, what might it mean?

This is visual studio C++, code that I did not write but that a coworker asked for help with debugging. The original was an earlier version but VS 2010 converted it. Could that be part of the problem?

I think the error means that the compiler cannot find something it is trying to link to... doesn't it? I just don't know what that something is. How do I fix this?


1>CmdView.obj : error LNK2019: unresolved external symbol "class Matrix<float> __cdecl Transpose(class Matrix<float> const &)" (?Transpose@@YA?AV?$Matrix@M@@ABV1@@Z) referenced in function "protected: void __thiscall CCmdView::OnCal(void)" (?OnCal@CCmdView@@IAEXXZ)

//I thought it might be the 'protected' keyword that was preventing access, but I have other errors in public functions

1>CmdView.obj : error LNK2019: unresolved external symbol "int __cdecl NumRows(class Matrix<float> const &)" (?NumRows@@YAHABV?$Matrix@M@@@Z) referenced in function "public: static int __cdecl Matrix<float>::pinv(class Matrix<float> &,class Matrix<float> &,class Matrix<float> &,class Matrix<float> &)" (?pinv@?$Matrix@M@@SAHAAV1@000@Z)



Thanks for any help/advice! :)

Is This A Good Question/Topic? 0
  • +

Replies To: error LNK2019: unresolved external symbol

#2 Hezekiah  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 207
  • View blog
  • Posts: 550
  • Joined: 12-July 09

Re: error LNK2019: unresolved external symbol

Posted 03 August 2012 - 05:54 AM

Quote

I think the error means that the compiler cannot find something it is trying to link to... doesn't it? I just don't know what that something is. How do I fix this?

That is correct, the symbols it can't find are:
Matrix<float> Transpose(const Matrix<float>&);
int NumRows(const Matrix<float>&);


Since the Matrix class is a template, I'll assume the functions are too. If this is the case, the functions must be implemented in the same translation unit in which they are called. This can be easily achieved by implementing them in the header files in which they are declared.
Was This Post Helpful? 1
  • +
  • -

#3 WabiSabi  Icon User is offline

  • D.I.C Head

Reputation: 51
  • View blog
  • Posts: 202
  • Joined: 31-December 10

Re: error LNK2019: unresolved external symbol

Posted 03 August 2012 - 07:18 AM

Thanks for the reply.

It looks like they already are declared and implemented in the same function (matrix.h)



//lots of code in between, of course

// friend template functions
template <typename T> int NumRows(const Matrix<T>& M);
	/////////////////////////////
	// friend functions
	/////////////////////////////
#ifdef __GNUC__
	friend int NumRows<T>(const Matrix<T>& M);
#endif

friend int NumRows(const Matrix<T>& M);

/////////////////////////////
// basic friend functions
/////////////////////////////
template <typename T> inline int NumRows(const Matrix<T>& M) {
	return M.m;
}



Also, it looks like it's using the friend declaration & not the template, because I get the same errors when I comment out the template.

//commenting this does not appear to change anything
//template <typename T> int NumRows(const Matrix<T>& M);

This post has been edited by WabiSabi: 03 August 2012 - 07:25 AM

Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 3993
  • View blog
  • Posts: 12,321
  • Joined: 25-December 09

Re: error LNK2019: unresolved external symbol

Posted 03 August 2012 - 07:48 AM

It might help if you posted the entire contents of the (matrix.h file.

Jim
Was This Post Helpful? 1
  • +
  • -

#5 WabiSabi  Icon User is offline

  • D.I.C Head

Reputation: 51
  • View blog
  • Posts: 202
  • Joined: 31-December 10

Re: error LNK2019: unresolved external symbol

Posted 03 August 2012 - 09:07 AM

Ok, though I'm not sure it will all be displayed here. It's > 3700 lines.

Yeah... it won't let me:

Quote

You have posted a message with more emoticons that this board allows. Please reduce the number of emoticons you've added to the message


It won't even let me post half of the code. And I can't attach the file either.


Quote

Matrix.h

You aren't permitted to upload this kind of file


Quote

Matrix.rar

You aren't permitted to upload this kind of file


ugh! :(

This post has been edited by WabiSabi: 03 August 2012 - 09:08 AM

Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is offline

  • member icon


Reputation: 3993
  • View blog
  • Posts: 12,321
  • Joined: 25-December 09

Re: error LNK2019: unresolved external symbol

Posted 03 August 2012 - 09:41 AM

Change the name to Matrix.txt and you should be able to attach the file.

Jim
Was This Post Helpful? 1
  • +
  • -

#7 WabiSabi  Icon User is offline

  • D.I.C Head

Reputation: 51
  • View blog
  • Posts: 202
  • Joined: 31-December 10

Re: error LNK2019: unresolved external symbol

Posted 03 August 2012 - 11:04 AM

Oh, so that's how you do it!

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#8 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1311
  • View blog
  • Posts: 4,503
  • Joined: 19-February 09

Re: error LNK2019: unresolved external symbol

Posted 03 August 2012 - 09:59 PM

Might be that the compiler is assuming the friend functions are non-templates.

Why do I get linker errors when I use template friends?


You could try defining the __GNUC__ macro in your code.

#define __GNUC__  


Was This Post Helpful? 1
  • +
  • -

#9 WabiSabi  Icon User is offline

  • D.I.C Head

Reputation: 51
  • View blog
  • Posts: 202
  • Joined: 31-December 10

Re: error LNK2019: unresolved external symbol

Posted 07 August 2012 - 11:10 AM

View Post#define, on 03 August 2012 - 10:59 PM, said:

Might be that the compiler is assuming the friend functions are non-templates.



You are correct.

I finally got it to compile by following the advice from your link. Thanks!
But I also had to put the <>'s wherever those functions were called & not just where they were defined.

Apparently it doesn't need the __GNUC__to be defined in order to compile.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1