我试图实现一个c++程序,该程序应该简单地输出一些文本并创建一个txt文件,然后将数据放入该文件中。我想在Windows中以.exe格式执行此文件。但是启动后崩溃立即显示以下错误:
用英语:“该程序不再起作用”。
我在CodeBlocks中对此进行了编码,并使用了GNU GCC编译器。
我实现了以下代码:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
cout << "Hello world! TEST" << endl;
std::ofstream of("TEXT.TXT");
of<<"Some text here"<<std::endl;
of.flush();
of.close();
std::cout<<"wrote the file successfully!"<<std::endl;
cout << "TEST Done" << endl;
}
调试器信息:
D:/Dokumente/Devlopement/CodeBlocks/Test1/bin/Debug/Test1.exe done Registered new type: wxString Registered new type: STL String Registered new type: STL Vector Setting breakpoints Debugger name and version: GNU gdb (GDB) 7.6.1 Child process PID: 10052 Program received signal SIGILL, Illegal instruction. In std::piecewise_construct () ()
1 0x0040147c in _fu0___ZSt4cout () at D:\Dokumente\Devlopement\CodeBlocks\Test1\main.cpp:10
D:\Dokumente\Devlopement\CodeBlocks\Test1\main.cpp:10:86:beg:0x40147c At D:\Dokumente\Devlopement\CodeBlocks\Test1\main.cpp:10
1 0x0040147c in _fu0___ZSt4cout () at D:\Dokumente\Devlopement\CodeBlocks\Test1\main.cpp:10
D:\ Dokumente \ Devlopement \ CodeBlocks \ Test1 \ main.cpp:10:86:beg:0x40147c
编译器版本mingw32-gcc-g++ 5.3.0-3
过去,当我第一次创建程序时,由于缺少一些dll而无法启动它。我必须将其放入文件夹(libgcc_s_dw2-1.dll,libstdc++-6.dll)中,它们是否会引起冲突?
请您参考如下方法:
好。我遇到了与dll冲突的问题。我把选项
-static-libgcc -static-libstdc++
在编译器选项/链接器设置/其他链接器选项中。似乎编译器现在将正确的dll放入exe文件,并且我不需要将错误的冲突dll放入同一路径。现在,它可以完美运行了。
谢谢。