Note that there are some explanatory texts on larger screens.

plurals
  1. POLinker errors for template macro: unresolved external symbol
    primarykey
    data
    text
    <p>I am trying to build someone else's code in VS2010. It builds fine in VS2005, but I need to upgrade it.</p> <p>They have defined a macro as follows in a header:</p> <pre><code>#include &lt;boost/scoped_ptr.hpp&gt; #include &lt;boost/utility.hpp&gt; #include &lt;boost/thread/once.hpp&gt; #define DEFINE_SINGLETON(name) boost::scoped_ptr&lt;name&gt; Singleton&lt;name&gt;::_instance template&lt;class T&gt; class Singleton : private boost::noncopyable { public: static T&amp; instance() { boost::call_once(init, flag); return *_instance; } static void init() { _instance.reset(new T()); } protected: Singleton() {} ~Singleton() {} private: static boost::scoped_ptr&lt;T&gt; _instance; static boost::once_flag flag; }; template&lt;class T&gt; boost::once_flag Singleton&lt;T&gt;::flag = BOOST_ONCE_INIT; </code></pre> <p>I've managed to get the code to build now, but I am getting lots of linker errors about this macro:</p> <pre><code>project1.lib(file1.obj) : error LNK2001: unresolved external symbol "private: static class boost::scoped_ptr&lt;class ClassABC&gt; Singleton&lt;class ClassABC&gt;::_instance" (?_instance@?$Singleton@VClassABC@@@@0V?$scoped_ptr@VClassABC@@@boost@@A) </code></pre> <p>An example of the macro being used (in source file):</p> <pre><code>#include "singleton.h" DEFINE_SINGLETON(ClassABC); </code></pre> <p>I am quite new to Boost and also to templates (sorry), so I cannot fathom why I'm getting these errors when it all linked fine in VS2005. Its worth noting, that in order to do the upgrade we have also had to upgrade our Boost version, so this could be a factor - a few checks already performed:</p> <ul> <li>Header file is included in source file</li> <li>Boost dir is added to include dirs (under VC++ dirs inproperty pages)</li> <li>Added boost lib dir to Linker -> General -> Additional library dependencies</li> </ul> <p>For info, I am compiling a Multi-threaded debug dll on Win32.</p> <p>I have spent most of the day googling to no avail, so any help greatly appreciated!</p> <p>Many thanks :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload