How can I update clang to 3.3 on Mac OS X 10.6 - macos

I'm running Mac OS X 10.6 and want to install TextMate 2, which is for Mac OS X 10.7+.
But all what it needs is a newer version of clang (LLVM), which is included in Lion and Mountain Lion. I read before here I can do that with MacPorts. So I used port install clang and MacPorts updated to clang-2.9, then clang-3.2 and finally clang-3.3. I thought, its updated now and I checked the version: clang --version. And it's not updated:
Apple clang version 2.0 (tags/Apple/clang-139) (based on LLVM 2.9svn)
Target: x86_64-apple-darwin10
Thread model: posix
So I copied the new clang file in this path (/opt/local/libexec/llvm-3.3/bin) to/usr/bin`. But now there's a fail :( :
dyld: Library not loaded: #executable_path/../lib/libLLVM-3.3svn.dylib
Referenced from: /usr/bin/clang
Reason: image not found Trace/BPT trap
The libLLVM-3.3svn.dylib is at /opt/local/libexec/llvm-3.3/lib. What can I do now, that
it runs clang-3.3? Sorry for my not perfect english ;) Thank you!

If you run clang from /usr/bin, it will be looking for the LLVM library in /usr/bin/../lib/libLLVM-3.3svn.dylib, i.e., /usr/lib/libLLVM-3.3svn.dylib (at least that's what the dynamic loader is telling you). You could try to copy the lib file into /usr/lib.
Alternatively, you can just download a more recent official build of Clang here:
http://llvm.org/releases/download.html
As far as I know, these builds are self-contained and do not need any dynamic libraries. However, it could be necessary to copy Apple's ARC libraries into a certain directory. If you run into trouble, please ask again.
Another approach is to build Clang and LLVM from source. You can find the repository URLs and instructions here:
http://clang.llvm.org/get_started.html
This should also build Clang with the LLVM libraries statically linked.
3.3, by the way, has not been officially released, so I would recommend using 3.2 unless you need any specific new features.

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.

How can I get boost to compile for an earlier deployment target on OSX?

this question has been asked before, but none of the answers seem to be currently working.. whether that's because they are incomplete, or things have changed, I don't know.
I build my code for a deployment target of 10.7 (my clients use their machines for music production, so they often prefer to stick with what they know works rather than updated with every new OS release).
I'm using boost.
So when I buid I get a bunch of warnings
ld: warning: object file (/usr/local/lib/libboost_filesystem.a(path.o)) was built for newer OSX version (10.10) than being linked (10.7)
ld: warning: object file (/usr/local/lib/libboost_system.a(error_code.o)) was built for newer OSX version (10.10) than being linked (10.7)
and so on.
So, I want to build boost (version 1.58 currently, unfortunately cmake is usually a couple of versions behind in what it can find) for a deployment target of 10.7
It seems the magic instruction is
macosx-version-min=10.7
except I can't make it work.
./bootstrap.sh
sudo ./b2 -a macosx-version-min=10.7 install
Just doesn't do it, nor do any of the other things I've tried (I'm not familar with how b2 works, so I'm grasping in the dark).
I expect I'm missing something simple, but some help would be much appreciated
regards
Jon
I ran into the same issue and could only fix it by building boost with the 10.7 library. I've used XCode 8.2.1. Here is what I did:
Modifying "Darwin.Jam". Look for this line: feature macosx-version-min : : propagated optional ;
and add this line below feature.extend macosx-version-min : 10.7 ;
Modify "Info.plist" in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform and set <key>MinimumSDKVersion</key>
<string>10.11</string>
Make sure your XCode.app has the 10.7 SDK installed. This is the right location: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs You can extract or copy it from an earlier version of XCode.
Now build boost with these options: cxxflags="-stdlib=libc++ -std=c++11 -mmacosx-version-min=10.7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk"
E.g. ./b2 -a cxxflags="-stdlib=libc++ -std=c++11 -mmacosx-version-min=10.7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk"
The solution above will build Boost with the 10.7 SDK instead just setting the Target SDK to 10.7

Compiling haskell with llvm

I'm starting to learn Haskell and I found out that ghc can compile using LLVM with the -fllvm flag. Whenever I use the flag, I get the error message:
<no location info>: error:
Warning: Couldn't figure out LLVM version!
Make sure you have installed LLVM 3.7
ghc: could not execute: opt
However, I have opt in my /usr/local/Cellar/llvm/3.9.0/ folder. I'm on a Mac OS X and I've installed the full LLVM with brew install llvm but error persists. Is this a genuine version problem where I have to unistall LLVM and reinstall its 3.7 version? Or is ghc having trouble finding opt and there is some kind of search path I can modify to fix the problem? Thanks for the help and have a great day.
The GHC documentation says that it's compatible with llvm-2.8+, but as you've discovered, it actually requires llvm-3.7.
The simplest way to get it is:
brew install llvm#3.7
This installs llvm binaries in your path with a -3.7 suffix, like clang-3.7. GHC will need the unadorned names, which are in a subdirectory:
export PATH=/usr/local/opt/llvm#3.7/lib/llvm-3.7/bin:$PATH

using command-line clang, OS X 10.9.1, Xcode 5.0.2

I'd like to use the -fsanitize=address features of clang.
I'm on:
OS X 10.9.1 with Xcode 5.0.2
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
I'm running clang from the command line, and I'm getting the error:
clang: error: unsupported argument 'address' to option 'fsanitize='
I'm told this works, but searching around hasn't shown me the way; do I need to bring in a different version of clang?
Thanks!
The out-of-box version of clang on OS X does not implement support of Address Sanitizer. You will have to build your own version of clang from sources.
You need a different build of clang than the one apple gave you. The simplest way to get one (or more) is to install Homebrew http://brew.sh
and then
brew install llvm --with-asan
You could also try a prebuilt clang from http://llvm.org/releases/download.htm.
It's by no means impossible to build clang 'by hand', but last I checked it did take multiple checkouts to get the source tree. The other options should have you asaning in minutes.

GDB debugging x86 Assembler code on OS X Mavericks

I've been trying to find an answer to this on stackoverflow for about an hour now, seems that a lot of similar problems are around but none really fitting to mine.
Information about what tools I'm using can be found further down!
I am writing my own compiler for a subset of the java language and thus creating assembler code. Now I'm at a point where I need to debug said assembler code to locate a bug. The problem is when I compile my assembler code to a binary with gcc -m32 -g myAssembler.s I get the following warning:
warning: no debug symbols in executable (-arch i386)
(This warning also occurs using -ggdb, -ggdb2, -ggdb3, -g2, -g3instead of -g
Since there are no debug symbols I can't use gdb to debug my code. I don't know much about linking and how it's done or who does it (especially on a Mac), so precise/noob-friendly answers would be very welcome.
Tools I'm using:
The assembly created from my compiler is x86, 32-bit GAS Syntax.
I am using OS X Mavericks with GNU gdb (GDB) 7.6 downloaded via MacPorts (They changed its name to ggdb. The ggdb --version command shows also a line saying :
This GDB was configured as "x86_64-apple-darwin13.0.0".
(Not quite sure if that's important.)
Running gcc --version returns:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
This is probably connected with Apple dropping support for GDB in Xcode 5 and you are using the version of gcc that comes with Xcode 5. You probably need to change compiler or debugger (to lldb)… you might look at llvm-gcc (which Xcode 5 also drops support for). Try www.llvm.org for a download. But that might be more trouble than using lldb (if your problem is indeed connected to Xcode 5's changes). Good luck! – CRD
I just downloaded gcc-4.2 from homebrew and that seems to work for lldb (which is still supported by Xcode 5 it seems). – Octoshape

Resources