|
Boost Users : |
Subject: Re: [Boost-users] unit test on vc++ 64 bit application
From: Richard (legalize+jeeves_at_[hidden])
Date: 2013-04-15 00:59:41
[Please do not mail me a copy of your followup]
boost-users_at_[hidden] spake the secret code
<1365797624390-4645257.post_at_[hidden]> thusly:
>I have build a 1.53 boost library for x64 and it seems works.
>
>But my unit test still not build successfully. But it looks like different
>issue.
>
>I have studio 2010 solution (just for my practice to use Boost Test) which
>include two simple win32 applications: one called MyMathApp and one for unit
>test called MyMathTest.
>
>In MyMathApp, it has class implemented in mymath.h / mymath.cpp. I want to
>unit test it in MyMathTest.
>
>In my MyMathApp, I have TestMyMath.cpp:
>
>#define BOOST_TEST_MAIN
>#include <boost/test/unit_test.hpp>
>
>#include "mymath.h"
>
>BOOST_AUTO_TEST_SUITE(CMyMathTests)
>
>BOOST_AUTO_TEST_CASE (test1)
>{
> CMyMath<int> m;
> BOOST_CHECK(m.add(2,3) == 5);
>}
>
>BOOST_AUTO_TEST_SUITE_END()
>
>I also add the mymath.h / mymath.cpp to my test project (not physically
>copy, just add to the project in solution explorer).
>
>When I build it, I got error:
>error LNK2019: unresolved external symbol "public: static int __cdecl
>CMyMath<int>::add(int,int)" (?add@?$CMyMath_at_H@@SAHHH_at_Z) referenced in
>function "public: void __cdecl CMyMathTests::test1::test_method(void)"
>(?test_method_at_constructortest1@CMyMathTests@@QEAAXXZ)
CMyMath is a template class, so all of it's definitions (not just
declarations) must be available at the point of instantiation so the
compiler can resolve the references.
It appears that your definition of CMyMath<T>::add(T,T) is only
declared and not defined in the .h you included. Additionally, it
appears that this was declared as a static method. That means you
didn't need an instance 'm' in order to call it, but there's no harm
done in calling it the way you did, just a little confusing to anyone
who reads this code as it will read like an instance method but it's
a static method that doesn't require an instance.
-- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net