C语言 C Hello world:Windows 上的代码块 IDE、MinGW C 编译器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22222566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C Hello world: Code Blocks IDE, MinGW C compiler on windows
提问by CL22
I can't get Code Blocks IDE to compile the hello world C program it creates when you create a new C project. I've installed MinGW and it was recognised by the IDE. But when I try to build I get the following output:
当您创建新的 C 项目时,我无法让 Code Blocks IDE 编译它创建的 hello world C 程序。我已经安装了 MinGW 并且它被 IDE 识别。但是当我尝试构建时,我得到以下输出:
-------------- Build: Debug in TestC3 (compiler: GNU GCC Compiler)---------------
mingw32-gcc.exe -Wall -g -c
C:\Users\jody\codeblocks\testc3\TestC3\main.c -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\TestC3.exe obj\Debug\main.o Execution
of 'mingw32-g++.exe -o bin\Debug\TestC3.exe obj\Debug\main.o' in
'C:\Users\jody\codeblocks\testc3\TestC3' failed.
Why is it trying to run mingw32-g++.exeas well as mingw32-gcc.exe? (And if it shouldn't be doing this, how can I configure it not to?)
为什么它试图运行mingw32-g++.exe以及mingw32-gcc.exe?(如果它不应该这样做,我该如何配置它不这样做?)
回答by Mike Kinghan
The mingw32-gcc.exestep is the compile step. The mingw32-g++.exeis the link step. This
is the correct sequence and will work if your mingw32installation is "normal" and correct - where "normal" means
you have installed the C++ as well as the C tools.
该mingw32-gcc.exe步骤是编译步骤。这mingw32-g++.exe是链接步骤。这是正确的顺序,如果您的mingw32安装是“正常”且正确的,它将起作用- 其中“正常”意味着您已经安装了 C++ 和 C 工具。
The link step is failing for you because mingw32-g++.execannot be executed, most likely because
it does not exist on your PATH. Try running mingw32-g++.exeat the command prompt to check.
Look in the directory where mingw32-gcc.exeresides to see if mingw32-g++.exeis also there.
链接步骤对您来说失败了,因为mingw32-g++.exe无法执行,很可能是因为它不存在于您的PATH. 尝试mingw32-g++.exe在命令提示符下运行以进行检查。查看所在的目录,mingw32-gcc.exe看看是否mingw32-g++.exe也在那里。
If your mingw32 installation has got broken somehow I suggest you uninstall and reinstall.
如果您的 mingw32 安装以某种方式损坏,我建议您卸载并重新安装。
If you have intentionallyinstalled only the C tools then that will explain what you are seeing, and it is easily fixed:
如果您有意只安装了 C 工具,那么这将解释您所看到的内容,并且很容易修复:
Both mingw32-gcc.exeand mingw32-g++.exeare just tool driver programs. When invoked
with compilation options for .cfiles, mingw32-gcc.exeinvokes the C compiler. When invoked
with compilation options for .cpp|cxx|...files, mingw32-g++.exeinvokes the C++ compiler. If
either of them is invoked with linkage options then it invokes the linker.
双方mingw32-gcc.exe并mingw32-g++.exe都只是工具的驱动程序。当使用.c文件的编译选项调用时,mingw32-gcc.exe调用 C 编译器。当使用.cpp|cxx|...文件的编译选项调用时,mingw32-g++.exe调用 C++ 编译器。如果使用链接选项调用它们中的任何一个,则它会调用链接器。
Codeblocks by default configures mingw32-g++.exeto invoke the linker because it will do equally
well for C projects, C++ projects and C/C++ projects, and it assumes you have the full C/C++ toolchain.
默认情况下,代码块配置mingw32-g++.exe为调用链接器,因为它对 C 项目、C++ 项目和 C/C++ 项目同样有效,并且假设您拥有完整的 C/C++ 工具链。
If you have not installed C++ tools and only want to build C, then you can use mingw32-gcc.exeto invoke both the C compiler and the linker. To configure this in the CodeBlocks IDE:
如果您还没有安装 C++ 工具并且只想构建 C,那么您可以使用mingw32-gcc.exe来调用 C 编译器和链接器。要在 CodeBlocks IDE 中进行配置:
- Navigate Settings-> Compiler
- Ensure that the Selected Compileris
GNU GCC - Tab to Toolchain executables
- Change Linker for dynamic libsfrom
mingw32-g++.exetomingw32-gcc.exe - OK out of Settingsand rebuild your project.
- 导航设置->编译器
- 确保选定的编译器是
GNU GCC - 工具链可执行文件的选项卡
- 更改链接的动态库从
mingw32-g++.exe到mingw32-gcc.exe - 确定设置并重建您的项目。
回答by Naveen Nirban Yadav
Firstly uninstall the codeblocks if you can't get something right. Move to codeblocks official site to download its minw.exe version so that you have a proper compiler for all of your C programs.
After installing go to Setting>Compiler>GNU GCC compiler.
Move to Toolchain Executables>.
Now set Compilers Installation Directory. Most probably it's C:\Program Files\CodeBlocks\MinGW\bin. Now you have to select and locate your C compiler as it is in the above mentioned directory.
After that rebulid and run your program.
如果您无法解决问题,请先卸载代码块。移至 codeblocks 官方站点下载其 minw.exe 版本,以便为所有 C 程序提供合适的编译器。安装后转到Setting>Compiler>GNU GCC compiler. 移至Toolchain Executables>。现在设置编译器安装目录。最有可能的是C:\Program Files\CodeBlocks\MinGW\bin。现在您必须选择并定位您的 C 编译器,因为它位于上述目录中。之后重新构建并运行您的程序。

