用IDE编译c++代码,第二次出现错误

Compile c++ code with IDE, error at the second time

本文关键字:第二次 错误 代码 IDE 编译 c++      更新时间:2023-10-16

我是Windows8系统中的新c++用户。我已经安装了MinGW并设置了环境变量。我创建了如下中最简单的hellow-world代码

    #include<iostream>
    #include<vector>
    using namespace std;
    int main(int argc, char **argv)
    {
        cout<<"hello world"<<endl;
        return 0;
    }

它在第一次运行时效果很好,但当我做一些小的修改时,例如删除"hello",然后重新构建并运行项目。我发现这个程序会一直运行下去。命令行不断显示:

    Current working directory: C:UserscrDocumentsprojecthelloworldDebug
    Running program: le_exec.exe ./helloworld

如果我尝试再次构建它,它会显示

    make.exe[1]: Entering directory 'C:/Users/cr/Documents/project/helloworld'
    C:/Users/cr/MinGW/bin/g++.exe  -c  "C:/Users/cr/Documents/project/helloworld/main.cpp" -g -O0 -Wall  -o ./Debug/main.cpp.o -I. -I.
    C:/Users/cr/MinGW/bin/g++.exe -o ./Debug/helloworld @"helloworld.txt" -L.
    c:/users/cr/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot open output file ./Debug/helloworld.exe: Permission denied
    collect2.exe: error: ld returned 1 exit status
    make.exe[1]: *** [Debug/helloworld] Error 1
    helloworld.mk:78: recipe for target 'Debug/helloworld' failed
    make.exe[1]: Leaving directory 'C:/Users/cr/Documents/project/helloworld'
    make.exe: *** [All] Error 2
    Makefile:4: recipe for target 'All' failed
    ====1 errors, 0 warnings====

我甚至无法删除可执行文件"helloworld.exe",因为在我重新启动计算机之前,它正在"系统"中使用。

更新:我可以在命令行中编译它:

    C:/Users/cr/Documents/project/helloworld>g++ main.cpp -o test.exe
    C:/Users/cr/Documents/project/helloworld>test.exe

然后它将一直运行,直到我关闭命令行窗口。如果我打开一个新的命令行窗口并再次编译该文件。没有问题。

更新2:当我第二次编译cpp文件时,即使该文件尚未编辑,也会出现问题。

C:/Users/cr/Documents/project/helloworld>g++ main.cpp -o test.exe
C:/Users/cr/Documents/project/helloworld>test.exe
hello world
C:/Users/cr/Documents/project/helloworld>g++ main.cpp -o test2.exe
C:/Users/cr/Documents/project/helloworld>test2.exe

它一直在这里运行。

谢谢大家,我为此奋斗了一整天。问题是防病毒软件。。。。。。我把它设置为非活动状态,一切都很好。。。我不想指出这个软件是什么,只是想提醒一下这个问题。。。。