tungsten icon indicating copy to clipboard operation
tungsten copied to clipboard

VS2013 compile error when you define the static const variable in class of head file

Open WindyPaper opened this issue 8 years ago • 3 comments

hi, when I fork your renderer and compile it with VS2013 on Windows, I found the compiler will encounter error of "the xxx(variable) already defined in core.lib". I think maybe the reason is you defined the variable in the head file and give them a value. Many people will give them value in cpp usually that won't cause these errors. Such as: the class "FileInputStreambuf" in FileStreamBuf.hpp have declared the varable "static CONSTEXPR size_t PutBackSize = 8", if FileUtil.cpp include this head file, when other files also include this head file, the compile will encounter the error of redefined. I want to know how you solve this error in your project, thank you very much!

WindyPaper avatar Jan 12 '17 15:01 WindyPaper

Hi,

I tested locally on VS2013 and VS2015, but did not encounter the same error. I also set up automated VS2013 builds recently to make sure, but the builds succeed. Is it possible that you modified the project, or do these errors also occur in a freshly cloned repository?

tunabrain avatar Feb 10 '17 16:02 tunabrain

Thanks for your reply. I do these errors in a freshly cloned repository. Maybe there are little different settings in my environment. I will test whether this error will encounter on VS2015.

WindyPaper avatar Feb 17 '17 02:02 WindyPaper

Yeah I am also getting the same (symbol already defined linker errors) on the latest (master) branch in VS2013. I am compilimg using vs2013 ultimate on Windows 8.1 64-bit. The code compiles and builds without errors on VS2015.

On VS2013, the solution is to comment the constant declaration line inside the namespace tungsten in the .cpp file. For example, in BitManip.cpp file

#include "BitManip.hpp"

#include <cmath>

namespace Tungsten {

//CONSTEXPR uint32 BitManip::LogMantissaBits; //comment this line

std::unique_ptr<float[]> BitManip::_logLookup;

BitManip::Initializer BitManip::initializer;

Just a suggestion, would it be better to put the TILE_SIZE variable in the parent class (Integrator) rather than declaring and defining in each child class?

mmmovania avatar Feb 18 '17 07:02 mmmovania