Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to properly use extern in a namespace?
    primarykey
    data
    text
    <p>I'm working on getting rLog to build as a DLL under windows, and I was getting undefined symbol errors relating to some global symbols in the rlog namespace. Specifically these in RLogChannel.cpp:</p> <pre><code>namespace rlog { ... RLogChannel *_RLDebugChannel = GetGlobalChannel( "debug", Log_Debug ); RLogChannel *_RLInfoChannel = GetGlobalChannel( "info", Log_Info ); RLogChannel *_RLWarningChannel = GetGlobalChannel( "warning", Log_Warning ); RLogChannel *_RLErrorChannel = GetGlobalChannel( "error", Log_Error ); ... }; </code></pre> <p>I assumed the problem was that 1) they weren't exported and 2) they weren't declared in the header so other things can access them. So I added a __declspec(dllexport) (via the RLOG_DECL macro) to them, and in the header, put:</p> <pre><code>namespace rlog { ... RLOG_DECL extern RLogChannel *_RLDebugChannel; RLOG_DECL extern RLogChannel *_RLInfoChannel; RLOG_DECL extern RLogChannel *_RLWarningChannel; RLOG_DECL extern RLogChannel *_RLErrorChannel; ... }; </code></pre> <p>But no matter how I declare the variables in RLogChannel.cpp I get a redefinition error, despite my externing them in the header... What's the right way to do this? Seems like it should be straightforward but I can't quite wrap my head around it.</p> <p>Edit: error message</p> <pre><code> Error 12 error C2086: 'rlog::RLogChannel *rlog::_RLDebugChannel' : redefinition rlog-1.4\rlog\RLogChannel.cpp 45 rlog </code></pre> <p>(same for all 4 symbols)</p> <p>Edit: I don't know what happened, the code is exactly the same before but now it will compile (feels like MSVC weirdness...), unfortunately the symbols still show up as unresolved when linking into my library</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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