Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

When instaliing mingw/gcc compiler from terminal then it gives Bad CPU type in executable error

This type of error will be given when installing compiler for c/c++ program


Use command for installing minnow/gcc compiler


Command 1: arch -x86_64 /bin/bash -c "$(curl -fsSL)"


Command 2: arch -x86_64 brew install mingw-w64


Error Given:

Error 1: arch: posix_spawnp: /bin/bash: Bad CPU type in executable

Error 2: brew: Bad CPU type in executable


[Link Edited by Moderator]


Posted on Oct 5, 2022 12:38 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 5, 2022 7:46 AM

If you install homebrew as per their instructions without any crap preceding their installation instructions, it will detect whether you are on an Intel or Apple Silicon platform, perform its installation accordingly (they are different), and detect that there is no Apple Command Line tools and relevant compiler (clang) installed and will do that for you. If you review the mingw-w64 opensource site, it offers a runtime environment for GCC on Windows, not macOS, and that is the root cause of that bad cpu type error message. Windows application binaries do not run in macOS.


Although brew can install GCC 12.* on macOS, you would have far less confusion and arguably better code using Apple's clang/clang++ compiler than GCC. Too many people over the last few years have confused or attempted to mix these compiler suites header and library files causing no small grief. That GCC build in homebrew may take an hour.


Apple's clang (or Swift) compiler is the drug of choice on macOS and can cross-compile for Intel, Apple Silicon, and using lipo(1) one can even produce a Universal2 binary with both architectures in it. You will receive little to no support here for third-party package managers, and alternative compiler suites that you install.



5 replies
Sort By: 
Question marked as Top-ranking reply

Oct 5, 2022 7:46 AM in response to guptaketan_

If you install homebrew as per their instructions without any crap preceding their installation instructions, it will detect whether you are on an Intel or Apple Silicon platform, perform its installation accordingly (they are different), and detect that there is no Apple Command Line tools and relevant compiler (clang) installed and will do that for you. If you review the mingw-w64 opensource site, it offers a runtime environment for GCC on Windows, not macOS, and that is the root cause of that bad cpu type error message. Windows application binaries do not run in macOS.


Although brew can install GCC 12.* on macOS, you would have far less confusion and arguably better code using Apple's clang/clang++ compiler than GCC. Too many people over the last few years have confused or attempted to mix these compiler suites header and library files causing no small grief. That GCC build in homebrew may take an hour.


Apple's clang (or Swift) compiler is the drug of choice on macOS and can cross-compile for Intel, Apple Silicon, and using lipo(1) one can even produce a Universal2 binary with both architectures in it. You will receive little to no support here for third-party package managers, and alternative compiler suites that you install.



Reply

Oct 5, 2022 8:32 AM in response to guptaketan_

The syntax error—the added space in the URL—highlighted in in yellow is the cause of the diagnostic highlighted in red.




Building Windows binaries on Mac is a whole lot of work, and the results are only really testable on Windows. Where it would also usually be easier to build the binaries.


Microsoft does not (yet?) have a supported and purchasable version of Windows available for Apple silicon, though there is an unsupported version available to Windows Insiders.

Reply

Oct 5, 2022 3:25 PM in response to guptaketan_

Homebrew, when installed properly will determine the platform architecture and use /usr/local for Intel installations, and the previously created /opt/homebrew for Apple Silicon installations. Still curious why you think you can install a mingw-w64 windows runtime environment for GCC on macOS and expect it to work.


For further support on homebrew, I suggest you contact its developers.

Reply

Oct 5, 2022 4:03 PM in response to guptaketan_

This also all requires mingw-w64 to cross-build its target Windows executables, too.


Finding same-architecture assumptions in the environment would not surprise.


Once you get homebrew installed—the above install sequence was incomplete, based on that twice-repeated curl command error—next contact mingw-64 and ask them for whether they expect this to work and then—if so—for assistance.

Reply

When instaliing mingw/gcc compiler from terminal then it gives Bad CPU type in executable error

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.