【发布时间】:2015-05-30 19:32:04
【问题描述】:
我最近决定学习 C/C++ 以准备几个月后将参加的编码课程,因此我下载并安装了 Eclipse。当我浏览 HelloWorld 项目的教程时,我遇到了一个问题,即使代码编译得很好,控制台也不会输出“HelloWorld!”。当我运行调试器时,它说它已终止,退出值为 -1073741515,后跟我的目录“C:\Users\Example\workspace\HelloWorld\Debug\HelloWorld.exe”,然后是日期和时间。
我安装了 MinGW,并将 eclipse 的路径设置为 C:\MinGW\bin,这是它在我的目录中的位置,我检查以确保我的偏好是正确的,因为在此之前我有一些“程序 g++ not在 PATH 中找到”和“在 PATH 中找不到程序 gcc” 当我更改环境变量时,这些错误已修复。
当我继续学习本教程时,以及包含此代码的 HelloWorld.cpp
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
接下来,他们让我写一个包含这段代码的 main.cpp
#include <iostream>
using namespace std;
int main() {
// Say Helloworld five times
for (int index = 0; index < 5; ++index)
cout << "HellowWorld!" << endl;
char input = 'i';
cout << "To exit, press 'm' then the 'Enter' key." << endl;
cin >> input;
while(input != 'm') {
cout << "You just entered '" << input << "'. "
<< "You need to enter 'm' to exit." << endl;
cin >> input;
}
cout << "Thank you. Exiting." << endl;
return 0;
}
最后,他们告诉我创建一个 makefile 来帮助构建和运行包含以下代码的项目:
all: hello.exe
clean:
rm main.o hello.exe
hello.exe: main.o
g++ -g -o hello main.o
main.o:
g++ -c -g main.cpp
这个程序应该做的只是打印出“HelloWorld!”在控制台中五次,但它不是,只是返回“终止,退出值:-1073741515”我真的很困惑为什么会这样。有人可以帮帮我吗?谢谢你们。
【问题讨论】:
-
建议在 makefile 的第一行之前插入以下行:'.PHONY: all clean'
-
你没有提到它,但是makefile应该命名为'makefile',然后运行makefile:'make -f makefile'或'make'
-
我认为,g++ 在 Windows 上运行时不会将“.exe”附加到生成的文件中。因此,建议将:'g++ -g -o hello main.c' 替换为 'g++ -g -o hello.exe main.o' 还建议将:'g++ -c -g main.cpp' 替换为:'g++ -c -g -o main.o main.cpp'
-
在尝试了这些修复程序后,我仍然遇到这些错误。我之前将makefile命名为“makefile”。谢谢大家的建议!如果它不能很快工作,我可能会尝试另一个 ide。
-
-1073741515是0xC0000135,也就是STATUS_DLL_NOT_FOUND。