Undefined reference to extern class?
<p>When using extern on classes it is giving me undefined reference, but when I make the function I'm calling from that class "static" it works fine. </p>

<p>Is there anyway to do it without using a static member function?</p>

<p>My test code:</p>

<pre><code>#include &lt;iostream&gt;

class MyClass
{
    public:
        void print() { std::clog &lt;&lt; "print()" &lt;&lt; std::endl; }
};

extern MyClass *g_myClass;

int main()
{
    g_myClass-&gt;print();
    return 0;
}
</code></pre>

<p>error:</p>

<pre><code>main.o:main.cpp:(.text+0x129): undefined reference to `_g_myClass'
</code></pre>

<p>In the actual code I'm getting a segmentation fault.</p>

<p>Backtrace:</p>

<pre><code>Program received signal SIGSEGV, Segmentation fault.
0x00465af2 in std::_Rb_tree&lt;Irc::Config::Config_t, std::pair&lt;Irc::Config::Config
_t const, std::string&gt;, std::_Select1st&lt;std::pair&lt;Irc::Config::Config_t const, s
td::string&gt; &gt;, std::less&lt;Irc::Config::Config_t&gt;, std::allocator&lt;std::pair&lt;Irc::C
onfig::Config_t const, std::string&gt; &gt; &gt;::_M_begin (this=0x0)
    at c:/qt/2010.04/mingw/bin/../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_tre
e.h:482
482           { return static_cast&lt;_Link_type&gt;(this-&gt;_M_impl._M_header._M_parent
); }
(gdb) bt
#0  0x00465af2 in std::_Rb_tree&lt;Irc::Config::Config_t, std::pair&lt;Irc::Config::Co
nfig_t const, std::string&gt;, std::_Select1st&lt;std::pair&lt;Irc::Config::Config_t cons
t, std::string&gt; &gt;, std::less&lt;Irc::Config::Config_t&gt;, std::allocator&lt;std::pair&lt;Ir
c::Config::Config_t const, std::string&gt; &gt; &gt;::_M_begin (this=0x0)
    at c:/qt/2010.04/mingw/bin/../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_tre
e.h:482
#1  0x0046596b in std::_Rb_tree&lt;Irc::Config::Config_t, std::pair&lt;Irc::Config::Co
nfig_t const, std::string&gt;, std::_Select1st&lt;std::pair&lt;Irc::Config::Config_t cons
t, std::string&gt; &gt;, std::less&lt;Irc::Config::Config_t&gt;, std::allocator&lt;std::pair&lt;Ir
c::Config::Config_t const, std::string&gt; &gt; &gt;::find (this=0x0, __k=@0x22fe40)
    at c:/qt/2010.04/mingw/bin/../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_tre
e.h:1421
#2  0x0045ec7c in std::map&lt;Irc::Config::Config_t, std::string, std::less&lt;Irc::Co
nfig::Config_t&gt;, std::allocator&lt;std::pair&lt;Irc::Config::Config_t const, std::stri
ng&gt; &gt; &gt;::find (this=0x0, __x=@0x22fe40)
    at c:/qt/2010.04/mingw/bin/../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_map
.h:659
#3  0x0040d376 in Irc::Config::getInt (this=0x0, arg=1) at configreader.cpp:72
#4  0x00405656 in Irc::Database::connect (this=0x483300) at database.cpp:30
#5  0x00406965 in main (argc=1, argv=0x3d3e18) at main.cpp:26
(gdb)
</code></pre>
