OK since MacOS 11, I've have never had much luck compiling stuff using the native Xcode compiler. I think this is due to the fact that Apple is using clang instead of gcc as the default compiler AND the fact the apple removed most all include files out of /usr/include and libraries out of /usr/lib and put these into a dynamic cache to speed up booting.
see: https://superuser.com/questions/1488979/macos-catalina-cannot-find-usr-include-file
As a result, I pretty much could not get anything to compile on Big Sur (11) or Monterey (12) using the standard compiler.
This really bothered me as I want to be able to compile my own apps (such as PHP, Apache, Mysql, or even Nethack/Slashem)
Now, I know what you are thinking... "John then install brew or MacPorts ... they setup a complete dev environment for you!" That's true, but the install ends up dumping like 5GB of files on your machine. That just seems a bit excessive ... in my opinion. The stuff I want... apache httpd, openSSL, php, mysql, nethack, is only like 1G tops.
The last version of MacOS with more/less a working dev environment (i.e. having complete files under /usr/include and /usr/lib) was OSX Mojave...
When I compiled executables on that platform .. .they always seemed to run on Big Sur and Monterey...
So this page documents my effort to compile gcc 11.3 on OSX Mojave and then to move it to MacOS 12 Monterey on the intel x86_64 platform.
If you don't feel like compiling this, and are ok with downloading and running unsigned code as root on your mac you can click the below links to just download the compiled executables.
Otherwise to build yourself ... proceed...
This is done on the following:
Create a VMware virtual machine, then boot from the DMG and install OSX 10.14 onto the VM.
Perform the following on the VM Mojave Server:
Login to the VM, open a terminal, then type gcc. This will install the xcode command line tools.
Once you are done. Verify the command line tools are installed by running the following:
$ ls -l /Library/Developer/CommandLineTools/SDKs/
sh-3.2# ls -l /Library/Developer/CommandLineTools/
total 0
drwxr-xr-x 5 root admin 160 Jul 12 2019 Library
drwxr-xr-x 3 root admin 96 Jul 12 2019 Packages
drwxr-xr-x 4 root wheel 128 Mar 17 06:57 SDKs
drwxr-xr-x 7 root admin 224 Jul 12 2019 usr
sh-3.2#
Extract all files to some install directory at the save level. For xz files use tar -Jxf [filename]. I used the directory ./apps
$ ls -l apps
total 0
drwxr-xr-x@ 84 jchung staff 2688 Apr 21 2022 gcc-11.3.0
drwxr-xr-x@ 130 jchung staff 4160 Mar 14 18:56 gmp-6.2.1
drwxr-xr-x@ 27 jchung staff 864 Mar 14 19:08 mpc-1.3.1
drwxr-xr-x@ 42 jchung staff 1344 Mar 14 19:00 mpfr-4.2.0
Build all required apps:
At this point all of the apps should be under /usr/local
Johns-MBP:~ jchung$ ls -l /usr/local
total 0
drwxr-xr-x 7 root wheel 224 Mar 18 06:42 gcc11
drwxr-xr-x 5 root wheel 160 Mar 17 18:20 gmp
drwxr-xr-x 5 root wheel 160 Mar 17 18:32 mpc
drwxr-xr-x 5 root wheel 160 Mar 17 18:30 mpfr
Now on the host, source .bash_profile and test compile HELLO WORLD.
$ cat test.c
#include
main() {
printf("hello world\n");
}
$ which gcc
/usr/local/gcc11/bin/gcc
$ gcc test.c
test.c:2:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
2 | main() {
| ^~~~
$ ./a.out
hello world
At this point, you are done. Using this, I was pretty much able to manually compile all of the apps that I needed.