【问题标题】:Cannot Compile "Hello World" in NetBeans IDE 7.3 with MinGW C++无法使用 MinGW C++ 在 NetBeans IDE 7.3 中编译“Hello World”
【发布时间】:2013-05-01 18:53:36
【问题描述】:

我正在尝试制作一个简单的“Hello World!”在 NetBeans IDE 7.3 中使用 MinGW 作为我的 C++ 编译器的程序。

我遇到了构建失败,我不知道为什么。

这是我的编译器设置:

  • 家庭:MinGW
  • 基本目录:C:\MinGW
  • C 编译器:C:\MinGW\bin\gcc.exe
  • C++ 编译器:C:\MinGW\bin\g++.exe
  • 汇编器:C:\MinGW\bin\as.exe
  • 制作命令:C:\MinGW\msys\1.0\bin\make.exe
  • 调试器命令:C:\MinGW\bin\gdb.exe

我已确保我的环境 PATH 指向 C:\MinGW\bin 和 C:\MinGW\msys\1.0\bin。

我的代码是:

#include <iostream>
using namespace std;
int main()
{
    cout << "Hello World!" << endl;
    return 0;
}

尝试构建项目后,我从 NetBeans 调试输出中收到此消息:

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/c/NetBeansProjects/HelloWorld'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/helloworld.exe
make[2]: Entering directory `/c/NetBeansProjects/HelloWorld'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
g++    -c -g -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
make[2]: g++: Command not found
make[2]: *** [build/Debug/MinGW-Windows/main.o] Error 127
make[2]: Leaving directory `/c/NetBeansProjects/HelloWorld'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/c/NetBeansProjects/HelloWorld'
make: *** [.build-impl] Error 2


BUILD FAILED (exit value 2, total time: 1s)

我搜索了各种问答,但我似乎做的一切都是正确的。

【问题讨论】:

  • C:\MinGW\bin\g++.exe 存在吗?
  • 确实如此。我对此感到很困惑。
  • 我没有使用过 NetBeans IDE。或许它需要一些特定的配置才能找到g++ 和朋友。或者,如果您最近更改了PATH,可能 NetBeans 没有您更新的PATH;在这种情况下,关闭并重新启动 NetBeans 可能会解决此问题。
  • 没有使用您配置的命令 - 您的设置中make 的位置是C:\MinGW\msys\1.0\bin\make.exe,但日志显示正在使用/usr/bin/make;您的设置表明 C++ 编译器是 C:\MinGW\bin\g++.exe,但正在调用 g++(没有路径)。您的编译器设置与项目尝试构建的方式之间存在重大脱节。
  • 啊!那行得通!我应该早点这样做。非常感谢您,汤普森先生!我会继续我的学业。

标签: c++ netbeans mingw


【解决方案1】:

右键单击我的电脑并选择属性。单击高级系统设置。系统属性对话框将打开。单击环境变量。编辑 PATH 变量并添加 C:\MinGW\msys\1.0\bin

【讨论】:

  • 单独安装的路径可能是C:\msys\1.0\bin。
【解决方案2】:

你在netbeans上的设置应该如下

Base Directory: C:\MinGW\bin 
C Compiler: C:\MinGW\bin\gcc.exe 
C++ Compiler: C:\MinGW\bin\g++.exe 
Fortran Compiler: C:\MinGW\bin\gfortran.exe 
Assembler: C:\MinGW\bin\as.exe 
Make Command: C:\MinGW\msys\1.0\bin\make.exe 
Debbuger Command: C:\MinGW\bin\gdb.exe

将这些添加到您的环境变量中

C:\MinGW\bin and C:\MinGW\msys\1.0\bin

如果您在安装 MINGW 和设置环境 PATH 之前/期间在 netbeans 上设置了设置,则可能会发生这种情况。

重启netbeans

【讨论】:

    【解决方案3】:

    你在安装后从mingw或sourceforge.net下载mysys,路径是C:\Mysys\1.0\bin\make.exe,在netbean ide中给出make编译器的路径。

    【讨论】:

    • 这不是解决此问题的方法
    猜你喜欢
    • 2013-04-25
    • 1970-01-01
    • 2018-09-12
    • 1970-01-01
    • 2014-11-27
    • 1970-01-01
    • 2021-02-21
    • 2014-11-29
    相关资源
    最近更新 更多