2

I have a LNK2019 in my c++ solution (VS2012). I have the following:

  • A static .lib with a class Matrix {...} inside
  • A dll which will consume this .lib. I have setup a project reference in the gui, and I can see the .lib being listed on the 'Command Line' property page under Linker.

I put the following simple code together

void Test()
{
    Matrix m(10,10);
    int z = m.Rows();
}

And this generates a LNK2019 looking for public: int __thiscall Common::Matrix::Rows(void) ....

What I don't understand is why the link error occurs: as far as I can see I have added the .lib reference, and setup all the headers etc required, but it just won't link. What have I missed?

valiano
  • 16,433
  • 7
  • 64
  • 79
Simon P
  • 1,196
  • 1
  • 12
  • 26
  • I am not sure, but maybe `dllimport`? – Bartek Banachewicz Nov 30 '12 at 18:17
  • Can you show a bit more? E.g. what is in your header, and how the Rows() function is defined in the Matrix class? I think I know the answer, but I need to check what you're currently doing. Most common problems are addressed in the MSDN docs: http://msdn.microsoft.com/en-us/library/799kze2z%28v=vs.110%29.aspx – Tawnos Nov 30 '12 at 18:28
  • @Tawnos: I noticed looking at my (old) code for Matrix.cpp that I had some inline modifiers - looking at your link that seems to be the problem. Do you want to add a response so I can mark it... thanks! – Simon P Nov 30 '12 at 18:40

1 Answers1

0

The MSDN documentation for LNK2019 should be able to help: http://msdn.microsoft.com/en-us/library/799kze2z%28v=vs.110%29.aspx

Tawnos
  • 1,877
  • 1
  • 17
  • 26
  • 1
    My exact problem I think was related to the following phrase: 'Similarly, a project that uses function inlining yet defines the functions in a .cpp file rather than in the header file will also get LNK2019. The header file is included everywhere deemed appropriate, but the functions are only inlined when the .cpp file passes through the compiler; therefore, the linker sees the functions as unresolved externals when used in other modules.' – Simon P Dec 01 '12 at 02:44