Using GCC in -m32 mode on mac OS - macos

I need to use gcc in -m32 mode on my macOS Mojave. I know it was deprecated some time ago. What should I do to make it possible?

You would need to download an older version of Xcode (eg. 9.x), and pre 10.14 SDK's (eg. 10.13), then try from there. Apple dropped Xcode capability/support for i386 in 10.14. In other words, Mojave can run existing 32-bit applications but can't build 32-bit applications anymore.
↳ MacPorts Discussion : User information about macOS Mojave

Works for me by installing:
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
as commented here: Can't compile C program on a Mac after upgrade to Mojave

Related

Is there any way to compile x86-64 + arm64 universal binaries in macOS 10.14?

The official way to compile universal binaries that target Apple's new M1 processor is to use Xcode 12, which requires at minimum macOS 10.15.4. I'm currently running macOS 10.14.6 though and do not want to upgrade if I can avoid it. Is there an unofficial way to compile such a universal binary when running macOS 10.14?
This is possible to do. Of course it can't be done with Xcode on its own since Apple has long since dropped support for macOS 10.14 in its developer tools, but can be down either by compiling from the command line or using another build system like cmake or qmake.
It at minimum requires two things:
A newer macOS SDK than is officially supported in macOS 10.14, obtained from Xcode 12.2 or later
A newer version of LLVM / clang that is compatible the macOS SDK from the version of Xcode you obtained
You can actually get both things by downloading the latest release of Xcode, since as of the time of this writing (December 2022) the release of LLVM included in the latest release of Xcode (14.2) will still run in macOS 10.14.
Should that ever stop working, though, or if you would prefer not to use Xcode's release of LLVM, you can also install a newer version of LLVM and clang using MacPorts, as MacPorts continues to support older macOS releases (unlike Homebrew). The command would be sudo port install clang-15, or whatever the latest available major release of clang is.
Another option is to built and install your own copy of LLVM and clang, and the steps to do so are laid out in LLVM's documentation.
For best results, the version of LLVM should be the same major version or newer than the version of LLVM / clang included in the release of Xcode you obtained.
Once you have both of those, you can compile C, C++, or Objective-C and probably Swift with a command like:
/path/to/newer/clang \
-arch x86_64 -arch arm64 \
-isysroot /path/to/Xcode14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
source.m source2.cpp source3.c ...
If you installed clang using MacPorts, then its path would be something like /opt/local/bin/clang-mp-15.
In the case of only using a newer release of Xcode, you can do it like this:
/path/to/Xcode14.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang \
-arch x86_64 -arch arm64 \
-isysroot /path/to/Xcode14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
source.m source2.cpp source3.c ...
I've only tested this with C, C++ and Objective-C so far, and not Swift, but presumably it will work for Swift as well.
Note that if you want to target macOS 10.14, it's still necessary to avoid using parts of the macOS SDK as well as C++ and Swift features that require macOS 10.15 or later.
(It may be possible to at least make use of newer C++ features in macOS 10.14 and earlier if you build your own universal binaries of LLVM's runtimes (namely libc++ and libc++abi) from the later release of LLVM, and then compile your code with the arguments -nostdlib, statically link to libc++ and libc++abi, and then explicitly link to /usr/lib/libSystem.B.dylib. But so far I haven't managed to get an arm64 copy of LLVM's runtimes to compile in macOS 10.14.)
Short answer: No
Why?
Apple did it. There's a doc from apple here
You will have to use Xcode 12.2 and above. You must upgrade to MacOS 10.15.4+ or 11 to benifit the latest feature.
Apple brings the tool lipo to convert binaires for ARM64 and AMD64 architectures.
With Apple silicon, you can compile binaries for ARM64 and AMD64. You can debug ARM64 binaries naturally. You can debug AMD64 binaries under Rosetta translation.
With Intel x86 chips, you can compile binaries for ARM64 and AMD64. You can debug AMD64 binaries naturally. But you cannot debug ARM64 binaries under Rosetta translation.
This means Apple Silicon's ARM64 architecture can do more on MacOS. It's unfair for AMD64 chips. Tipical Apple. Hopefully someone can come out and unseals the secret Apple silicon. But I don't think apple would like to share. If Intel/AMD wake up and bring us more powerful chips which can compile/debug ARM64 binaries for MacOS, apple wouldn't be happy with their sales. For the longterm, we won't be able to do it (seemingly). Apple kicked Nvidia away years ago, now Intel, soon AMD. Mark it here. 10 years later, let's see.

Mac OS Catalina gfortran - "ld: library not found for -lgcrt1.o"

I'm compiling a fortran program on Mac (10.15.2) with cmake and gfortran, but I'm getting the following error:
ld: library not found for -lgcrt1.o
I found the file grcrt1.o in the folder
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/gcrt1.o
But even if I add that to my PATH it still doesn't work.
The version of gfortran I'm using was installed with homebrew and is in
/usr/local/bin/gfortran
gfortran is version 9.2.0
This just happened to me as well. I have Xcode 11 and 10.1 installed. For me switching back to version 10.1 helped:
sudo xcode-select --switch /Applications/Xcode-10.1.app/

how to compile fox-toolkit with glx.h in mac osx

I am trying to build Fox-toolkit with opengl support in Mac OSX mountain lion (10.8). I have modified the configure file from
GL/gl.h
GL/glu.h
To
OpenGL/gl.h
OpenGL/glu.h
and it can find those two files during the configure. However it cannot find glx.h with none of GL/glx.h, OpenGL/glx.h and GLUT/glx.h
I have XQuartz installed with proper linking. I can see glx.h at /opt/X11/include/GL/glx.h, but the fox-toolkit ./configure cannot find it. How to solve this problem?
GLX is the OpenGL extension protocol extension for X11. While MacOS X has a X11 server, it's OpenGL support it not so good. You certainly want to use MacOS X native OpenGL framework. Which means: No GLX!
I don't know Fox toolkit very well, but it might be (somebody shed some light on this please), that it doesn't contain support for OpenGL widgets on MacOS X yet.
After long search and try, finally I have found the solution to this problem at sourceforge
According to Anders F Björklund (many thanks to him) in the post above-
For 10.7 Lion and beyond, the commands are-
CXXCPP="g++ -E" CXX="g++ -arch i386 -arch x86_64"
CPPFLAGS="-I/usr/X11/include -I/usr/X11/include/freetype2" LDFLAGS="-L/usr/X11/lib" ./configure --with-x --with-xft --with-opengl --x-includes=/usr/X11/include --x-libraries=/usr/X11/lib
make
make install

How can I compile a library in 32bit on a 64bit Mac machine (Mountain Lion)

I want to compile tesseract http://code.google.com/p/tesseract-ocr/ in 32bit on my Macbook. But I have a 64bit Mac OS Mountain Lion machine.
There is a Makefile, and I tried:
(1) $ ./configure --with-arch=i386
(2) $ $./configure --build=i386-apple-darwin --host=i386-apple-darwin --target=i386-apple-darwin
Both didn't work. The library compiled is still 64bit. Actually for (2) I see, after running the ./configure, it says somethings like "checking for i386-apple-darwin-g++ .. no", actually everything it checked for i386 had a "no" in the end. But the compilation succeed, just the library does not seem to be 32bit.
Anyone can help with this?
Try the -m32 to specify building 32-bit executables in the CFLAGS and CXXFLAGS. However, the MacOSX sdks for 10.7 and 10.8 don't have 32-bit i386 code to link against (only MacOSX10.6.sdk). I recommend using macports to install/build the tesseract engine on Mac OS X 10.7+.

How to compile for Mac OS X 10.5

I'd like to compile my application for version 10.5 and forward. Ever since I upgraded to Snow Leopard and installed the latest XCode, gcc defaults to 10.6. I've tried -isysroot /Developer/SDKs/MacOSX10.5.sdk but that doesn't seem to work. Is there a GCC flag that allows me to set the SDK?
(Incidentally, I changed the gcc symbolic link to point to gcc-4.0 instead of gcc-4.2 and it worked but I thought I could tell the latest GCC to compile for an older SDK).
Thanks,
Rui
In XCode you only need to set the deployment target to OSX 10.5.
For gcc you need to set -mmacosx-version-min=10.5.

Resources