Registered Member
|
I am writing a class that will exist in a static library. I want to write some unit tests for this static library and class. I have chosen GTest as my unit testing harness.
I have a static method in the class called kronecker (Klass::kronecker). It takes two const Eigen::MatrixBase parameters. When I reference the Klass::kronecker method inside of my tests I get a linker error saying the method is undefined (LNK2001: unresolved external symbol). I feel like this has something to do with my lack of understanding regarding the templating used by Eigen. HELP?
|
Registered Member
|
I don't know GTest so it's a bit hard to comment. However, are you sure it is okay to put the implementation of the template method in the .cpp file? Does the compiler not need access to the implementation when instantiating your class during the compilation of klass_test (this has nothing to do with Eigen).
|
Registered Member
|
I probably should not have brought up GTest that is just a mis-direction to what the real problem is.
The same error occurs if I just write a simple console program that links against my library. It will complain:
When I look at the dumpbin output the kronecker method does not appear in my library. I think that this: http://cboard.cprogramming.com/cplusplu ... tions.html is the answer to what ales me. What is more I don't think I can do anything about it. |
Moderator
|
Could you provide the complete "console" test. In your initial post, jitseniesen was write about the fact that the Klass::kronecker function must be defined in the .h file, not in a cpp file. If you do, you have to rely on explicit template instantiations and instantiate the class for all the types you plan to use.
Btw, in the unsupported/ folder of Eigen there already is a kronecker product implementation. |
Registered Member
|
The console test program I was talking about would be this:
Well basically, it came down to my lack of understanding of how a C++ template actually works. I never realized that they only really exist at compile time and therefore must be written in the header. So what I did to solve this was to implement the PIMPL idiom. Then in my unit testing cases include the *.cpp file; so I could compile and link the tests. Also, I would prefer to use the Eigen built-in Kronecker method. However, in my Eigen folder I cannot find the method. I ran `grep -r -i kronecker ./` on the unsupported directory and nothing came back. |
Moderator
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]