当我从VS2013迁移我的项目时,我观察到一些奇怪的错误.这里是一个新创建的项目来重现它的简化代码:
A.cpp:
#include <iostream> extern void foo(); int main() { std::cout << "some text from main" << std::endl; foo(); }
B.cpp:
#include <iostream> void foo() { std::cout << "some text from foo" << std::endl; }
重要的是添加项目有“禁用语言扩展”设置为是(/ Za).没有这个设置,它是正确的bulding.
1>B.obj : error LNK2005: "public: static bool const std::numeric_limits<short>::is_signed" (?is_signed@?$numeric_limits@F@std@@2_NB) already defined in A.obj 1>B.obj : error LNK2005: "public: static int const std::numeric_limits<short>::digits" (?digits@?$numeric_limits@F@std@@2HB) already defined in A.obj 1>B.obj : error LNK2005: "public: static int const std::numeric_limits<short>::digits10" (?digits10@?$numeric_limits@F@std@@2HB) already defined in A.obj 1>B.obj : error LNK2005: "public: static bool const std::numeric_limits<unsigned short>::is_signed" (?is_signed@?$numeric_limits@G@std@@2_NB) already defined in A.obj 1>B.obj : error LNK2005: "public: static int const std::numeric_limits<unsigned short>::digits" (?digits@?$numeric_limits@G@std@@2HB) already defined in A.obj 1>B.obj : error LNK2005: "public: static int const std::numeric_limits<unsigned short>::digits10" (?digits10@?$numeric_limits@G@std@@2HB) already defined in A.obj 1>B.obj : error LNK2005: "public: static bool const std::numeric_limits<char16_t>::is_signed" (?is_signed@?$numeric_limits@_S@std@@2_NB) already defined in A.obj 1>B.obj : error LNK2005: "public: static int const std::numeric_limits<char16_t>::digits" (?digits@?$numeric_limits@_S@std@@2HB) already defined in A.obj ...
这似乎表明,< iostream>的VS实现标题以一些讨厌的方式打破了一个定义规则.是对的,还是我缺少一些明显的东西?