gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:19:54 24 4
gpt4 key购买 nike

下面一段代码,用于生成素数,在运行调试时按预期编译和运行,但在 Release模式下构建时似乎总是使着墨器崩溃:

#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 Files\Microsoft SDKs\Windows\v6.0A\bin\mt.exe'.

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

更新:经过进一步审查,即使是简单的“Hello World”代码,mt.exe 似乎在 Release 模式下对我来说一直崩溃,所以我的安装一定有问题。我将重新安装所有希望能解决这个问题的东西。主持人,请随时关闭此问题。

最佳答案

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

关于c++ - Visual C++ 链接器崩溃 (VS2008 SP1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6193198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com