Visual C++链接器崩溃(VS2008 SP1)

Visual C++ linker crashes (VS2008 SP1)

本文关键字:VS2008 SP1 崩溃 C++ 链接 Visual      更新时间:2023-10-16

以下代码用于生成素数,在运行调试时按预期编译和运行,但在发布模式下构建时似乎总是会崩溃:

#include <vector>
#include <algorithm>
#include <cstdlib>
#include <iostream>
template<typename T> class PrimeGen {
    struct Elim {
        T p ;
        T e ;
    } ;
    class Elim_cmp {
    public:
        bool operator()(const Elim& e1, const Elim& e2) { return e1.e > e2.e; }
    } ;
    std::vector<Elim> elim_heap ;
    T last ;
public:
    PrimeGen() {
        Elim e0 = { 2, 4 } ;
        elim_heap.reserve(1024) ;
        elim_heap.push_back(e0) ;
        last = 2 ;
    }
    T next() {
        T n = last ;
        bool prime;
        do {
            n ++ ;
            prime = true ;
            while(n == elim_heap.front().e) {
                if(prime) prime = false ;
                std::pop_heap(elim_heap.begin(), elim_heap.end(), Elim_cmp()) ;
                Elim& elim = elim_heap.back() ;
                elim.e = elim.p + n ;
                std::push_heap(elim_heap.begin(), elim_heap.end(), Elim_cmp()) ;
            }
        } while(!prime) ;
        Elim e = { n, 2*n } ;
        elim_heap.push_back( e ) ;
        std::push_heap(elim_heap.begin(), elim_heap.end(), Elim_cmp()) ;
        return last = n ;
    }
} ;
int main()
{
    using namespace std ;
    PrimeGen<unsigned int> pgen ;
    for(int i=0; i<100; i++) {
        cout << pgen.next() << endl ;
    }
    system("pause") ;
}

有人明白为什么会发生这种事吗?或者我遇到过这样一种罕见的情况,编译器而不是代码应该受到谴责?

我得到的错误如下:

error PRJ0002 : Error result -1073741819 returned from 'C:Program FilesMicrosoft SDKsWindowsv6.0Abinmt.exe'.

如果其他运行VisualStudio的人花时间尝试在发布模式下构建代码(我已经删除了任何外部依赖项,所以应该只是c&p),我会非常感激。

更新:经过进一步审查,即使是简单的"Hello World"代码,mt.exe在发布模式下似乎也会不断崩溃,所以我的安装肯定有问题。我要重新安装所有有望解决这个问题的东西。主持人,请随意结束这个问题。

某些程序(如防病毒程序)在链接器尝试嵌入清单文件的同时扫描file.exe。