c++ - IncrCalcPtrs 期间的内部错误 - 当我第二次运行代码时不会再次发生

标签 c++

保存代码的项目具有所有默认的 MSVS2008 设置。

考虑以下代码,我使用这些代码来熟悉各种 STL 产品:

#include <vector>
#include <iostream>
#include <numeric>

using namespace std;


template <class T> void print(const vector<T>& l)
{  // A generic print function for vectors
    cout << endl << "PV Size of vector is " << l.size() << "\n[";
    for(int i = 0; i < l.size(); i++)
    {
        cout<<l[i]<<",";
    }
    cout << "]\n";
}


int main()
{
    vector<double> vec1(4, 2.0);
    vector<double> vec2(4, 4.0);
    double init = 0.0;
    double summation = accumulate(vec1.begin(), vec1.end(), init);
    cout<<"Summation = "<<summation<<", init is "<<init<<endl;

    double ip = inner_product(vec1.begin(), vec1.end(), vec2.begin(), init);
    cout<<"ip = "<<ip<<", init is "<<init<<endl;

    int size = 6;
    int seed_value = 2;
    vector<int> vec3(size, seed_value);
    vector<int> result(size);
    partial_sum(vec3.begin(), vec3.end(), result.begin());
    cout<<"The partial sum of vec3 is ";
    print(vec3);

    int sz = 10;
    int value = 2;
    vector<int> vec4(sz);
    for(int it = 0; it < vec4.size(); it++){
        vec4[it] = value;
        value++;
    }
    vector<int> result2(vec4.size());
    adjacent_difference(vec4.begin(), vec4.end(), result2.begin());
    cout<<"Adjacent differenec of vec4 is ";
    print(vec4);

    return(0);
}

我第一次尝试运行此程序(在 Windows 7、Visual Studio 2008 下)时出现以下错误:

c:\programming\numeric_algorithms_on_vectors.cpp(86) : warning C4018: '<' : signed/unsigned mismatch

c:\programming\numeric_algorithms_on_vectors.cpp(37) : warning C4018: '<' : signed/unsigned mismatch

c:\programming\numeric_algorithms_on_vectors.cpp(81) : see reference to function template instantiation 'void print(const std::vector<_Ty> &)' being compiled

        with
        [
            _Ty=int
        ]

Linking...

numeric_algorithms_on_vectors.obj : fatal error LNK1000: Internal error during     IncrCalcPtrs
  Version 9.00.30729.01
  ExceptionCode            = C0000005
  ExceptionFlags           = 00000000
  ExceptionAddress         = 00E6B8C0 (00E10000) "C:\Program Files (x86)\Microsoft     Visual Studio 9.0\VC\bin\link.exe"
  NumberParameters         = 00000002
  ExceptionInformation[ 0] = 00000000
  ExceptionInformation[ 1] = 0000001C
CONTEXT:
  Eax    = 00000000  Esp    = 0042EAE8
  Ebx    = 3FFF0000  Ebp    = 0042EB04
  Ecx    = 77CB36FA  Esi    = 4000AF9C
  Edx    = 4000F774  Edi    = 00000000
  Eip    = 00E6B8C0  EFlags = 00010293
  SegCs  = 00000023  SegDs  = 0000002B
  SegSs  = 0000002B  SegEs  = 0000002B
  SegFs  = 00000053  SegGs  = 0000002B
  Dr0    = 00000000  Dr3    = 00000000
  Dr1    = 00000000  Dr6    = 00000000
  Dr2    = 00000000  Dr7    = 00000000

然而,在点击提示我的代码未正确编译/工作的窗口后,当我再次调试相同的代码而不对代码进行任何更改时,程序可以正常运行。代码第一次不能编译/链接/运行,但下一次运行完美的原因是什么?

最佳答案

这是 VS2008 SP1 链接器中的一个已知问题。修复在VS2010,反馈报告is here .

我自己见过几次,只有当它实际以增量方式链接时才会发生。对我来说,它总是通过强制通过 Build + Rebuild 进行完整构建来自行解决,以便删除并重新创建 .ilk 文件。如果这仍然不适合您,那么您可以使用“项目 + 属性”、“链接器”、“常规”、“启用增量链接”关闭该功能。

关于c++ - IncrCalcPtrs 期间的内部错误 - 当我第二次运行代码时不会再次发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4292013/

相关文章:

c++ - 带有多个定界符的字符串流

c++ - 将 lambda 放在静态初始化列表中并通过引用捕获是否安全?

c++ - 这些类型有什么问题?

c++ - 创建类对象的 vector 时何时调用构造函数?

c++ - 解锁对 STL vector::size 安全性的访问

c++ - rint 不存在于 Visual Studio 2010 math.h 中,相当于 CUDA rint

c++ - 如何检查线程是否已在 C++11 及更高版本中完成工作?

c++ - 为用户定义类型的 shared_ptr 专门化标准库函数是否合法?

c++ - 禁止多次创建线程

python - C++ 中的 Crypto++ :Encrypt in Python , 解密