【发布时间】:2014-08-05 19:12:09
【问题描述】:
我正在尝试编译此 C++ 代码,但没有成功。使用 MinGW 和 Netbeans 7.4。该代码没有意义,因为我将所有内容都删除到最低限度以进行故障分析。问题似乎是“#include”行。当它在那里时,项目会构建,但不会创建 .exe。如果它不存在,则项目构建并运行良好。
有什么想法吗?顺便说一句,我读了其他“不能包括
main.cpp
#include "xmessage.h"
using namespace std;
int main() {
xmessage();
return 0;
}
xmessage.cpp
#include <iostream> // What's wrooong with you, <iostream> !?!?
using namespace std;
void xmessage () {
int i = 1;
}
xmessage.h
#ifndef XMESSAGE_H
#define XMESSAGE_H
void xmessage ();
#endif /* XMESSAGE_H */
还有:
文件是 .cpp,不是这样。
如果我从包含文件夹中删除 iostream 文件 C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++ 构建失败。所以这肯定是编译器正在使用的文件。
Netbeans 输出:
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/admin/Documents/NetBeansProjects
/project125(HeaderFileMacros) - WIP'
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows
/project125_headerfilemacros__-_wip.exe
make.exe[2]: Entering directory `/c/Users/admin/Documents/NetBeansProjects
/project125(HeaderFileMacros) - WIP'
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/project125_headerfilemacros__-_wip build/Debug/MinGW-Windows
/main.o build/Debug/MinGW-Windows/xmessage.o
make.exe[2]: Leaving directory `/c/Users/admin/Documents/NetBeansProjects
/project125(HeaderFileMacros) - WIP'
make.exe[1]: Leaving directory `/c/Users/admin/Documents/NetBeansProjects
/project125(HeaderFileMacros) - WIP'
构建成功(总时间:4s)
【问题讨论】:
-
您必须在
xmessage.cpp中包含xmessage.h。有留言吗?还要确保你已经设置了一个 C++ - 而不是 C - 项目。 -
我将 xmessage.cpp 更改为 #include "xmessage.h" #include
// 你怎么了, !?!?使用命名空间标准;无效 xmessage () { int i = 1;并且我还更改了两个包含行的顺序。两种情况的结果都和以前一样。 -
请确保我使用您的代码创建了一个项目并对其进行了编译。正如您所料:一切正常。那么,能否请您发布 Netbeans 的 build 输出?
-
有一个 main.o、xmessage.o 和 xmessage.o.d。我无法发布内容,因为它们是二进制的。我也没有看到发布文件的选项。很抱歉这么无助。 Xmessage.o.d.包含这个: build/Debug/MinGW-Windows/xmessage.o: xmessage.cpp xmessage.h xmessage.h:
-
问题在另一个线程中解决了(你在这里叫它吗?)我在创建一个简单的makefile时遇到问题(因为我想听从你的建议,但不知道很多关于makefile)。用户 RobKennedy 认为它是一个过度渴望的文件系统监视器,这正是它的本来面目。我的 Avast Antivir 处于静默模式,它会将每个新的 .exe 文件都置于隔离区,而不会通知我。如何关闭此/突出显示解决方案??
标签: c++ netbeans compilation mingw iostream