2

I have created a static library with the files alien.h and alien.cpp below. That library is linked by the file user.cpp. If one removes the line with the comment, then the code compiles, links, and runs as expected. As it is, the library and the program compile, the program however does not link. MSVC2015RC generates over 100 errors about std::numeric_limits being already defined.

Is there some setting that I should be aware of or is this a MSVC2015 bug?

File alien.h

#include <vector> // This line causes troubles.

struct alien
{
    const int * const value;
};

extern alien meh;

File alien.cpp

alien meh { 7 };

File user.cpp

#include "alien.h"
#include <iostream>
#pragma comment(lib, "alien.lib")

int main()
{
    wcout << meh.value;
    return 0;
}

Error LNK2005 "public: static int const std::numeric_limits::max_exponent" (?max_exponent@?$numeric_limits@M@std@@2HB) already defined in alien.obj

Hector
  • 2,464
  • 3
  • 19
  • 34

1 Answers1

6

It is a bug! The same library/program compiles under MSVC2013 without language extensions enabled. In MSVC2015, language extensions must be enabled.

Hector
  • 2,464
  • 3
  • 19
  • 34
  • Thank you for this. I've been tearing my hair out trying to build icu, and see that it's referenced directly in the bug report. – Roger Leigh Aug 05 '15 at 15:38
  • I have the exact same problem in VS2015. Removing the /Za flag in all my modules didn't solve it - any ideas? – SirKnigget Oct 08 '15 at 10:04
  • @SirKnigget: check the workaround [here](https://connect.microsoft.com/VisualStudio/feedback/details/1331482/bug-in-stl). Basically, you need to modify one of VS headers. – Hector Oct 08 '15 at 10:14