C++ 在 Windows 8 64 位中设置 MingW 和 Code::Blocks

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16716454/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 20:35:07  来源:igfitidea点击:

Setting up MingW and Code::Blocks in Windows 8 64 bit

c++codeblocksmingw-w64

提问by Rohit Jain

I am trying to setup MingWand Code::Blockson my Windows 8 64 bitlaptop, and I'm facing some problem while building a main.cppfile. These are the versions that I have installed:

我正在尝试在我的Windows 8 64 位笔记本电脑上设置MingWCode::Blocks,但在构建文件时遇到了一些问题。这些是我安装的版本:main.cpp

I've set the path to mingw64\binin the environment variable. Also, in the Code::Blocks compiler settings, I have set path for all ToolChain Executables. There are two gccin the MingWbin path. One is - gcc.exeand other is - x86_64-w64-mingw32-gcc.exe. Same for C++ Compiler, Linker for static and dynamic libs. Now when I try to build a simple Hello Worldfile, it shows some errors:

我已经mingw64\bin在环境变量中设置了路径。此外,在 Code::Blocks 编译器设置中,我为所有ToolChain Executables设置了路径。有两个海湾合作委员会MingW平台bin路径。一个是 -gcc.exe另一个是 - x86_64-w64-mingw32-gcc.exeC++ Compiler相同,静态库和动态库的 Linker相同。现在,当我尝试构建一个简单的Hello World文件时,它显示了一些错误:

obj\Debug\main.o -- In function swscanf  

c:\mingw\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32.7.3\..\..\..\..\x86_64-w64-mingw32\include\wchar.h -- undefined reference to `__gxx_personality_sj0'

obj\Debug\main.o -- In function `wscanf':

c:\mingw\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32.7.3\..\..\..\..\x86_64-w64-mingw32\include\wchar.h -- undefined reference to `__gxx_personality_sj0'

Similarly there are many errors and undefined references for - fwprintf, wprintf, std:cout, etc..

同样存在许多误区和未定义的引用- ,fwprintfwprintfstd:cout等。

I'm sure there is some configuration problem, but I cannot find out what's the issue. Can any one take a look at the problem.

我确定存在一些配置问题,但我无法找出问题所在。任何人都可以看看这个问题。

Here's the code I'm running:

这是我正在运行的代码:

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}

回答by mrmoje

If you don't require 64 bit support, consider downloading "codeblocks-12.11mingw-setup.exe"
It packs its own 32 bit mingw and has everything preconfigured for you.

Otherwise, if you still need to compile amd64 apps:-
Assuming you extracted to D:\Mingw64, under the "Tool Chain Executables" tab, set the "Compiler's Installation Directory" to "D:\Mingw64\bin", Then click auto-detect to check whether code::blocks likes what it finds.

如果您不需要 64 位支持,请考虑下载“codeblocks-12.11mingw-setup.exe”
它打包了自己的 32 位 mingw 并为您预先配置了所有内容。

否则,如果你仍然需要编译amd64应用程序:-
假设你解压到D:\Mingw64,在“Tool Chain Executables”选项卡下,将“Compiler's Installation Directory”设置为“D:\Mingw64\bin”,然后点击auto -detect 来检查 code::blocks 是否喜欢它找到的东西。

If everythings Ok, make sure the rest of the fields are as follows:-

如果一切正常,请确保其余字段如下:-

C compiler: x86_64-w64-mingw32-gcc.exe
C++ compiler: x86_64-w64-mingw32-g++.exe
Linker for dynamic libs: x86_64-w64-mingw32-g++.exe
Linker for static libs: x86_64-w64-mingw32-ar.exe
Debugger: GDB/CDB Debugger... 
Ressource compiler: x86_64-w64-mingw32-windres.exe
Make program: mingw32-make.exe

Click on the "Additional Paths" tab and enter the following line:- (the path is correct for ver 4.7.4,the one you downloaded. It ends with 4.7.3)

单击“其他路径”选项卡并输入以下行:-(路径对于版本 4.7.4 是正确的,即您下载的版本。以 4.7.3 结尾)

D:\Mingw64\libexec\gcc\x86_64-w64-mingw32.7.3\ 

Click on the "Search directories" tab to the imediate left "Toolchain Executables"
Add the following paths:-

单击左侧“工具链可执行文件”的“搜索目录”选项卡,
添加以下路径:-

D:\Mingw64\include
D:\Mingw64\x86_64-w64-mingw32\include
D:\Mingw64\x86_64-w64-mingw32\include\c++.7.3
D:\Mingw64\x86_64-w64-mingw32\include\c++.7.3\backward
D:\Mingw64\x86_64-w64-mingw32\include\c++.7.3\x86_64-w64-mingw32
D:\Mingw64\lib\gcc\x86_64-w64-mingw32.7.3\include

Click on the "linker" tab and add the following paths:-

单击“链接器”选项卡并添加以下路径:-

D:\Mingw64\Lib 
D:\Mingw64\x86_64-w64-mingw32\lib

And finally click on the "Compiler Settings tab", Click on "Other options" and add:-

最后单击“编译器设置选项卡”,单击“其他选项”并添加:-

-m64

One last thing-> remember to save those settings to disk!
If it crashes while you test this new config, you might wish you had!
Do this (I think) either by "File->Save Everything" or restarting code::blocks ...without another instance running.

最后一件事-> 记住将这些设置保存到磁盘!
如果它在您测试这个新配置时崩溃,您可能希望自己有!
执行此操作(我认为)通过“文件->保存所有内容”或重新启动 code::blocks ...而无需另一个实例运行

Try compiling something then share the outcome

尝试编译一些东西然后分享结果

回答by Shaikh Shees Hassan

Peace! Dear brother, I think you need this:

和平!亲爱的兄弟,我想你需要这个:

(1) std::cout << "Hello world!" << std::endl;

(1) std::cout << "Hello world!" << std::endl;

You need to put "std::function_name" whenever you are using a predefined function from iostream.h, because this is you way access it in GCC, which Code::Blocks uses.

每当您使用 iostream.h 中的预定义函数时,您都需要放置“std::function_name”,因为这是您在 Code::Blocks 使用的 GCC 中访问它的方式。

(2) Try it compiling by omitting "using namespace std;" from your code. Because I've compiled C and C++ code many times in Code::Blocks on 32-bit Windows XP, and it did!

(2) 尝试通过省略“using namespace std;”进行编译 从你的代码。因为我已经在 32 位 Windows XP 上的 Code::Blocks 中多次编译了 C 和 C++ 代码,而且它做到了!

(3) Make sure the path is set to the directory "mingw\bin".

(3) 确保路径设置为目录“mingw\bin”。

(4) Ensure if you have 64-bit MinGW installed and path set to its "bin" directory (if you want to compile for 64-bit). It will compile for 64-bit by default.

(4) 确保您安装了 64 位 MinGW 并将路径设置为其“bin”目录(如果您想编译为 64 位)。默认情况下,它将编译为 64 位。

(5) Try the flags/arguments "-m32" and "-m64" for compiling for 32- and 64-big respectively.

(5) 尝试使用标志/参数“-m32”和“-m64”分别为 32- 和 64-big 编译。