64位可执行程序编译报错求助:cc1plus.exe不支持64位模式
Hey there! I totally get how confusing this can be when you're starting out with C++ and compiler settings. Let's break down what's going on and how to fix it:
Why this error happens
The CodeBlocks version you're using probably comes with a 32-bit-only MinGW compiler pre-installed. Even though your Windows 10 system is 64-bit, the compiler itself doesn't have the code to generate 64-bit executables—so when you try to use the -m64 flag (or tick the 64-bit option in CodeBlocks), it throws that error. Without the flag, it defaults to 32-bit, which is why your code compiles fine.
Step-by-step fix
1. Install a 64-bit-capable MinGW-w64 compiler
You'll need to replace the default 32-bit MinGW with a MinGW-w64 build that supports 64-bit compilation. Look for official MinGW-w64 pre-built packages (make sure to pick the x86_64 architecture version—this targets 64-bit systems). When choosing, you can go with:
- Thread model:
posix(better for C++11+ thread support) orwin32(works well for most standard Windows apps) - Exception model:
seh(recommended for 64-bit Windows, it's more efficient)
Extract the downloaded package to a folder on your system (like C:\mingw-w64—avoid spaces in the path to prevent unexpected issues).
2. Configure CodeBlocks to use the new compiler
Open CodeBlocks and follow these steps:
- Go to Settings > Compiler
- Switch to the Toolchain executables tab
- Click the ... button next to "Compiler's installation directory" and select the
mingw64folder inside your MinGW-w64 installation (e.g.,C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64) - Double-check the executable paths below (C Compiler should be
gcc.exe, C++ Compiler should beg++.exe, etc.—they should auto-update if you picked the right directory) - Click OK to save the settings
3. Test the 64-bit compilation
Create a quick test program to verify everything works:
#include <iostream> int main() { std::cout << "Size of pointer: " << sizeof(void*) << " bytes\n"; return 0; }
- Tick the 64-bit option in CodeBlocks (the one you tried before)
- Compile and run the program. If it outputs
Size of pointer: 8 bytes, you're successfully compiling 64-bit executables!
Quick notes
- Uninstall or remove the old 32-bit MinGW from your system if you can—this avoids path conflicts.
- If you run into issues finding pre-built MinGW-w64 packages, you can also use MSYS2 to install it (just search for
mingw-w64-x86_64-gccin the MSYS2 package manager).
内容的提问来源于stack exchange,提问作者JohnDoe122

