如何在代码块中的.cpp文件中创建.exe? [英] How do I create a .exe from a .cpp file in Code Blocks?
问题描述
我刚开始学习C ++,并显示我发现的代码输出这个方法。这工作时,我第一次编译的Programme.cpp的结构:
I've just started learning C++, and to display the outputs of code I found this method. This worked when I first compiled Structure of a Programme.cpp:
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
它给了我一个.exe,我打开,跑,可爱的'Hello World!'出现,但是当我试图编译第二个时,Variables.cpp:
It gave me a .exe, which I opened, ran, and got a lovely 'Hello World!' appearing, but when I tried compiling a second one, Variables.cpp:
#include <iostream>
using namespace std;
int main ()
{
int a, b;
int result;
a=5;
b=2;
a=a+1;
result=a-b;
cout << result;
return 0;
}
我没有得到一个.exe,所以不能工作如何打开它。我试过重新编译Programme.cpp的结构(删除所有相关文件后),但现在不会再创建.exe了。创建的唯一文件是Programme.o和Variables.o的结构(在子目录obj \Debug)。
I didn't get a .exe at all, so couldn't work out how to open it. I tried re-compiling Structure of a Programme.cpp (after deleting all the associated files), but now that won't create a .exe anymore, either. The only files created are Structure of a Programme.o and Variables.o (in a sub-directory obj\Debug).
我可以找到的唯一问题似乎类似这,但问题似乎有点不同,我试图删除其中一个文件(所以在文件夹中只有一个Programme.cpp或Variables.cpp的结构),我仍然相同的结果。
The only question I could find that seemed similar was this, but the problem seems to be slightly different, and I tried deleting one of the files (so there was only one of Structure of a Programme.cpp or Variables.cpp in the folder) and I still had the same result.
此外,没有任何文件的编译器错误,我不认为我改变了程序结构之间的代码块中的任何选项工作和一切无效。
Also, there were no compiler errors with either file, and I don't think I changed any options in Code Blocks between Structure of a Programme working and everything not working.
感谢,
Dalkius
编辑:构建日志:
Compiling: Structure of a Programme.cpp
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings
Compiling: Variables.cpp
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings
编辑2:'完整命令行'生成日志:
edit 2: 'Full Commandline' build logs:
Build started on: 14-12-2011 at 07:57.39
Build ended on: 14-12-2011 at 08:01.03
-------------- Clean: Debug in cplusplus.com Tutorial ---------------
Done.
mingw32-g++.exe -Wall -g -c "D:\My Documents\0HOME\Programming\C++\Code Blocks\cplusplus.com Tutorial\Structure of a Programme.cpp" -o "obj\Debug\Structure of a Programme.o"
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 0 warnings
mingw32-g++.exe -Wall -g -c "D:\My Documents\0HOME\Programming\C++\Code Blocks\cplusplus.com Tutorial\Variables.cpp" -o obj\Debug\Variables.o
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings
推荐答案
从查看更新的构建日志,似乎没有执行链接步骤来生成最终的可执行文件。有几件事你可以检查和一些想法尝试:
From looking at your updated build log, it appears the linking step isn't being performed to generate the final executable. There are a couple of things you can check and some ideas to try out:
- 确保链接器可执行文件和正确的路径设置为C :: B可以找到它。对于MinGW,链接器通过名为g ++。exe的编译器驱动程序调用。
- 检查是否选择了控制台应用程序下类型。
- 如果一切看起来还好,但它仍然请尝试创建一个新的空白控制台项目。
- 尝试从cmd命令提示符处手动构建,以确保工具链本身正常工作。你应该在你的mingw安装下找到一个'mingwvars.bat'脚本。运行该脚本以打开正确的命令行环境。使用此命令进行简单测试编译:
- Make sure the linker executable and proper path is set so C::B can locate it. For MinGW the linker is invoked through the compiler driver named 'g++.exe'.
- Check that 'Console application' is selected under 'Type'.
- If everything looks okay but it still doesn't link try creating a new blank console project. Add the existing files to that project and try building it.
- Try building it manually from a 'cmd' command prompt to make sure the toolchain itself is functioning. You should find a 'mingwvars.bat' script under your mingw install. Run that script to open up a proper commandline environment. Do a simple test compile using this command:
cdD:\ My Documents \0HOME \Programming\C ++ \Code Blocks\cplusplus.com教程
g ++。exe -Wall -g Variables.cpp -o Variables.exe
cd "D:\My Documents\0HOME\Programming\C++\Code Blocks\cplusplus.com Tutorial"
g++.exe -Wall -g Variables.cpp -o Variables.exe
最后,这是你的日志应该大致看起来当它正确建立:
Lastly, this is what your log should approximately look like when it's building correctly:
这篇关于如何在代码块中的.cpp文件中创建.exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!