[CONFIG] static const definitions
On 2/27/2013 5:09 AM, boost-users-request-at-lists.boost.org |Boost/Allow to home| wrote:
In fact even when initialized inline, an out of line definition should always be provided as different compilers have different ideas about what constitutes "use" of the variable (rather than just the value). MSVC pretty much never requires an out-of-line definition for example, where as GCC will often generate linker errors if you don't provide it. The problem is that MSVC is _prohibiting_ an out-of-line definition! (Visual Studio 2010)
On Wed, Feb 27, 2013 at 11:02 AM, John M. Dlugosz
On 2/27/2013 5:09 AM, boost-users-request-at-lists.boost.org |Boost/Allow to home| wrote:
In fact even when initialized inline, an out of line definition should always be provided as different compilers have different ideas about what constitutes "use" of the variable (rather than just the value). MSVC pretty much never requires an out-of-line definition for example, where as GCC will often generate linker errors if you don't provide it.
The problem is that MSVC is _prohibiting_ an out-of-line definition! (Visual Studio 2010)
Exactly, hence my suggestion for performing a preprocessor check around the out-of-line definition. I suppose it would be nice to have a BOOST-y preprocessor def that could let you know if this is the case... Brian
On 2/27/2013 5:09 AM, boost-users-request-at-lists.boost.org |Boost/Allow to home| wrote:
In fact even when initialized inline, an out of line definition should always be provided as different compilers have different ideas about what constitutes "use" of the variable (rather than just the value). MSVC pretty much never requires an out-of-line definition for example, where as GCC will often generate linker errors if you don't provide it. The problem is that MSVC is _prohibiting_ an out-of-line definition! (Visual Studio 2010)
I've not come across that one before - do you have an example? John.
On Thu, Feb 28, 2013 at 1:34 AM, John Maddock
On 2/27/2013 5:09 AM, boost-users-request-at-lists.boost.org |Boost/Allow to home| wrote:
In fact even when initialized inline, an out of line definition should always be provided as different compilers have different ideas about what constitutes "use" of the variable (rather than just the value). MSVC pretty much never requires an out-of-line definition for example, where as GCC will often generate linker errors if you don't provide it.
The problem is that MSVC is _prohibiting_ an out-of-line definition! (Visual Studio 2010)
I've not come across that one before - do you have an example?
John. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Simple example, does not link in VS 2012: //example.h #ifndef example_H_ #define example_H_ struct example { static const int foo0 = 0; static const int foo1 = 1; }; #endif//example_H_ //example.cpp #include "example.h" const int example::foo0; const int example::foo1; //main.cpp #include "example.h" int main(int argc, char **args) { example e; return e.foo0; } //errors: 1> Compiling... 1> example.cpp 1> Generating Code... 1>example.obj : error LNK2005: "public: static int const example::foo0" (?foo0@example@@2HB) already defined in main.obj 1>example.obj : error LNK2005: "public: static int const example::foo1" (?foo1@example@@2HB) already defined in main.obj 1>c:\users\budgeb\documents\visual studio 2012\Projects\Project1\Debug\Project1.exe : fatal error LNK1169: one or more multiply defined symbols found 1>
participants (3)
-
Brian Budge
-
John M. Dlugosz
-
John Maddock