[Units] Bug with BOOST_UNITS_STATIC_CONSTANT and precompiled headers on MSVC
I think that I've run across a bug, either in Units, or in MSVC.
Because it only appears when precompiled headers are in use, I suspect
it may be a bug in MSVC. Basically, if BOOST_UNITS_STATIC_CONSTANT is
used in a header that is compiled into the precomiled header, there will
be linker errors.
Here is my information:
Microsoft Windows XP Professional x64 Edition
Microsoft Development Environment 2003 Version 7.1.6030
Microsoft Visual Studio .NET 2003 Service Pack 1 (KB918007)
Below is the minimial code to reproduce the error. There are 4 files,
stdafx.h, stdafx.cpp (which is used to create the pch), a.cpp, and
b.cpp. The same code without precompiled headers turned on links fine.
// start of stdafx.cpp
#include "stdafx.h"
// end of stdafx.cpp
// start of stdafx.h
#ifndef STDAFX_H_328A91DC_3924_466E_80EA_C9BB6CBF7638
#define STDAFX_H_328A91DC_3924_466E_80EA_C9BB6CBF7638
#include
,void>::boost::unit
>,struct boost::units::dimensionless_type>,struct boost::units::homogeneous_system > >,struct boost::units::list > > > > > > > > >,void> const & const boost::units::si::`anonymous namespace'::meter" (?meter@?A0x490e06d9@si@units@boost@@3ABV?$unit@U?$list@U?$dim@Ulength_base_dimension@units@boost@@V?$static_rational@$00$00@23@@units@boost@@Udimensionless_type@23@@units@boost@@U?$homogeneous_system@U?$list@Umeter_base_unit@si@units@boost@@U?$list@U?$scaled_base_unit@Ugram_base_unit@cgs@units@boost@@U?$scale@$09V?$static_rational@$02$00@units@boost@@@34@@units@boost@@U?$list@Usecond_base_unit@si@units@boost@@U?$list@Uampere_base_unit@si@units@boost@@U?$list@Ukelvin_base_unit@si@units@boost@@U?$list@Umole_base_unit@si@units@boost@@U?$list@Ucandela_base_unit@si@units@boost@@U?$list@Uradian_base_unit@angle@units@boost@@U?$list@Usteradian_base_unit@angle@units@boost@@Udimensionless_type@34@@34@@34@@34@@34@@34@@34@@23@@34@@units@boost@@@23@X@34@B) already defined in stdafx.obj unit2.obj : error LNK2005: "class unit >,struct boost::units::dimensionless_type>,struct boost::units::homogeneous_system > >,struct boost::units::list > > > > > > > > ,void>::boost::unit >,struct boost::units::dimensionless_type>,struct boost::units::homogeneous_system > >,struct boost::units::list > > > > > > > > >,void> const & const boost::units::si::`anonymous namespace'::meter" (?meter@?A0x490e06d9@si@units@boost@@3ABV?$unit@U?$list@U?$dim@Ulength_base_dimension@units@boost@@V?$static_rational@$00$00@23@@units@boost@@Udimensionless_type@23@@units@boost@@U?$homogeneous_system@U?$list@Umeter_base_unit@si@units@boost@@U?$list@U?$scaled_base_unit@Ugram_base_unit@cgs@units@boost@@U?$scale@$09V?$static_rational@$02$00@units@boost@@@34@@units@boost@@U?$list@Usecond_base_unit@si@units@boost@@U?$list@Uampere_base_unit@si@units@boost@@U?$list@Ukelvin_base_unit@si@units@boost@@U?$list@Umole_base_unit@si@units@boost@@U?$list@Ucandela_base_unit@si@units@boost@@U?$list@Uradian_base_unit@angle@units@boost@@U?$list@Usteradian_base_unit@angle@units@boost@@Udimensionless_type@34@@34@@34@@34@@34@@34@@34@@23@@34@@units@boost@@@23@X@34@B) already defined in stdafx.obj
Any insights would be appreciated. Thanks, David
AMDG David Walthall wrote:
I think that I've run across a bug, either in Units, or in MSVC. Because it only appears when precompiled headers are in use, I suspect it may be a bug in MSVC. Basically, if BOOST_UNITS_STATIC_CONSTANT is used in a header that is compiled into the precomiled header, there will be linker errors.
Here is my information: Microsoft Windows XP Professional x64 Edition Microsoft Development Environment 2003 Version 7.1.6030 Microsoft Visual Studio .NET 2003 Service Pack 1 (KB918007)
Fixed in svn. Thanks for reporting this. In Christ, Steven Watanabe
Steven Watanabe wrote:
Fixed in svn. Thanks for reporting this.
In Christ, Steven Watanabe
I looked a the fix, but I don't understand enough about the technique to avoid ODR violations to know if you corrected a bug in Units or if you implemented a workaround for a buggy compiler. That is, should I patch the 1.37 code or is just avoiding BOOST_UNITS_STATIC_CONSTANT in precompiled headers sufficient? Thanks, David
AMDG David Walthall wrote:
I looked a the fix, but I don't understand enough about the technique to avoid ODR violations to know if you corrected a bug in Units or if you implemented a workaround for a buggy compiler.
It's a workaround for a buggy compiler.
That is, should I patch the 1.37 code or is just avoiding BOOST_UNITS_STATIC_CONSTANT in precompiled headers sufficient?
In Christ, Steven Watanabe
participants (2)
-
David Walthall
-
Steven Watanabe