在静态库中包含STL

Hec*_*tor 2 c++ stl static-libraries c++11

我创建了一个静态库,下面是alien.h和alien.cpp文件.该库由user.cpp文件链接.如果删除带注释的行,则代码将按预期编译,链接和运行.实际上,库和程序编译,但程序没有链接.MSVC2015RC会生成超过100个std::numeric_limits已定义的错误.

是否有一些我应该注意的设置或者这是一个MSVC2015错误?

文件alien.h

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

struct alien
{
    const int * const value;
};

extern alien meh;
Run Code Online (Sandbox Code Playgroud)

文件alien.cpp

alien meh { 7 };
Run Code Online (Sandbox Code Playgroud)

文件user.cpp

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

int main()
{
    wcout << meh.value;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误LNK2005"public:static int const std :: numeric_limits :: max_exponent"(?max_exponent @?$ numeric_limits @ M @ std @@ 2HB)已在alien.obj中定义

Hec*_*tor 6

这是一个错误!在没有启用语言扩展的MSVC2013下编译相同的库/程序.在MSVC2015中,必须启用语言扩展.