We want our software to support OSX Versions down to 10.9. In XCode you can set the target version, that is no problem, but we have another lib that gets linked in the projekt which is built using cmake. Now XCode complains that the lib is build for 10.11, but our project is 10.9. Can I somehow tell clang on the command line to compile for an older version?
The only information I have found is to set OSX_VERSION as variable, but it seems to have no effect.
Thanks in advance!
From clang --help:
-mmacosx-version-min=<value>
Set Mac OS X deployment target
Do be on the lookout for gotchas with earlier deployment targets, and make sure you test all the OS versions you support.
Related
I've been building Clang for years on Linux and OS X. From the LLVM Download page, I've always used the following sources:
LLVM (LLVM source)
Compiler Front End (Clang source)
Compiler RT (Runtime source)
Compiler Tools (Tools Extra sources)
The recipe I am using to download, build and install Clang 3.5 can be found at Clang 3.5 download, build and install script.
Its works great on OS X 10.7 and 10.8, and I've never needed the libc++ gear on OS X 10.7.x or 10.8.x (that's about 2010 or so through current).
Question: when does one need the libc++ and libc++ ABI sources?
I'm trying to help troubleshoot the inability to compile a simple C++ "Hello World" program on OS X 10.9. Clang 3.5 installed in /usr/local (just like the others), but its failing to find headers (like <iostream>) and it encounters undefined symbols during link (like "std::ostream::operator<<(std::ostream& (*)(std::ostream&))").
I'm wondering if 10.7 and 10.8 had headers and libraries where previous versions of Clang expected, but 10.9 needs them built and installed.
Question: is this symptomatic of a missing libc++ and libc++ ABI?
You should have the libc++ sources checked out when building/installing clang such that you will also install the C++ STL.
If you don't have a libc++ runtime on your system, you should checkout and install libc++abi and libc++ which can be done standalone and independently of their checkout in your llvm/clang install.
As reference, I suggest you take a look at the libcxxabi, libcxx, libunwind, and llvm-X.Y ports in MacPorts which show how I've configured these projects to build on Leopard through Yosemite.
After I upgraded my Mac OS X to Mountain Lion (all the way from Snow Leopard) and XCode 5 (all the way from XCode 3.2) I can no longer build a C++ project that I used to build in XCode successfully. I get loads of errors now all saying "Parse issue: Unknown type name *" for different objects. I tried an older version of XCode (4.6) and set the SDK to Mac OS X 10.7. This problem was solved but not using the latest version of XCode caused other problems.
To be specific, the errors (at least the first ones) seem to be related to Carbon graphic library. I don't know if that matters. I know that Carbon is somehow outdated but an official release of the application I'm extending runs on Mac OS 10.8 so I wonder why I can't build the code on 10.8.
What can be the cause of this error? The code is big and is not written by me so changing it is not an option. I really need to build it on XCode 5 or else I should downgrade my OS!
Several things that have been long deprecated in Carbon were finally removed in the Mac OS X 10.7 SDK.
You will need the Mac OS X 10.6 SDK to build your project. Apple stopped automatically including older SDKs with newer versions of Xcode but you can download older Xcode versions (from Apple's Developer site) and one of them...maybe Xcode 4.3 or so...will have the 10.6 SDK.
In order to use an older SDK with a newer Xcode, you must install it manually. The correct location is:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
Also note, any upgrade to Xcode (such as an update downloaded from the App Store) will obliterate your manually-installed SDKs. I recommend archiving the ones you need somewhere else so you can replace them as needed.
I heavily use the c++0x/c++11 features in my project, particularly code blocks and shared pointers. When I upgraded my OS to 10.8 Mountain Lion (Edit: From 10.7), I was forced to upgrade Xcode. In upgrading Xcode, I lost the ability to compile my c++ project for deployment on 10.6 systems as I get the following error.
clang: error: invalid deployment target for -stdlib=libc++ (requires Mac OS X 10.7 or later)
It appears that Apple is trying to force people to upgrade by not allowing developers to support Snow Leopard. This makes me angry. Arrrggg!!!
What can I do?
EDIT: After several comments back and forth, it should be made clear that 10.6 does not ship with system libc++ libraries. As a result, simply being able to build a libc++ project for 10.6 deployment is not enough. You would also need to include libc++ binaries with your 10.6 distribution or statically link to them. So lets continue with the premise that I am already doing that.
UPDATE 1: This question was originally intended for use with Xcode 4.5.2 (the latest version at the time the question was asked). I have since upgraded to Xcode 4.6.3 and have updated the question and answer to reflect that.
UPDATE 2: I've since upgraded to Xcode 5.0.2. The technique listed in the selected answer below still works as expected.
UPDATE 3: I've since upgraded to Xcode 5.1. The technique listed in the answer below does not yet work for this version!
UPDATE 4: I've since upgraded to Xcode 6.0.1. The technique listed in the selected answer below appears to be working again.
UPDATE 5: I've since upgraded to Xcode 7.1.1. The technique listed in the selected answer below appears to be working again, with one important caveat. You must disable Bitcoding used for AppThinning since the opensource LLVM version doesn't support it (nor should it). So you will need to switch between the open source and Apple LLVM clang in order to compile for both 10.6 and tvOS/watchOS (since Bitcoding is required for those OSes).
Apple has decided to only officially support libc++ on 10.7 or higher. So the version of clang/llvm that ships with Xcode checks to see if the deployment target is set for 10.6 when using libc++, and prevents you from compiling. However, this flag is not included in the open source version of clang/llvm.
Take a look at this thread:
http://permalink.gmane.org/gmane.comp.compilers.clang.devel/17557
So, to compile a project that is using c++11 for 10.6 deployment, you need to give Xcode the open source version. Here is one way of doing it:
Download the open source version of clang from here (use LLVM 3.1 for Xcode 4.5.x; use LLVM 3.2 for Xcode 4.6.x; use LLVM 3.3 for Xcode 5.0.x; use LLVM 3.5.0 for XCode 6.0.1; use LLVM 3.7.0 for XCode 7.1.1):
http://llvm.org/releases/download.html
Make a backup of Xcode's default clang compiler and put it in a safe place (In case you screw up!)
This is located at:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
Replace the default clang compiler with the one you downloaded from [1]
chown the clang binary for root:wheel with sudo chown root:wheel clang from the bin directory listed in [2].
Startup Xcode and compile!
UPDATE #1: This technique does not currently work for Xcode 5.1 or newer, which relies on LLVM 3.4. When I get some more time, I will try and find a solution to post here. But if someone comes up with a solution before me, they should post it as an answer.
UPDATE #2: Unfortunately I can't remember if I ever found a solution for Xcode 5.1, however I can confirm that the technique does still work for Xcode 6.0.1. I haven't tested on versions newer than that, but it could still work.
UPDATE #3: This technique appears to still work with XCode 7.1.1 using LLVM 3.7.0. However, the open source LLVM clang does not support Bitcoding. So you will need to switch between the open source compiler and Apple's compiler in order to develop for both 10.6 and tvOS/watchOS (which require Bitcoding).
P.S.: The Mac OS X binaries for LLVM 3.4 and 3.5.0 are listed as "Clang for Darwin 10.9" at www.llvm.org/releases/download.html rather than as "Clang Binaries for Mac OS X" in previous versions.
While Xcode 4.5.x is the current default version on OS X 10.8, you can have other, older versions of Xcode, such as Xcode 3.2.6 for OS X 10.6, available on 10.8 as long as you have access to their installers. You will need to ensure you install each one to a unique directory. Also, one thing you can't or shouldn't do is to install the Command Line Tools component or installer package of older Xcodes onto your 10.8 system, i.e. not into /usr or /System/Library. You can use the xcodebuild, xcode-select, and xcrun command line tools to access non-default Xcode components. See their man pages for more info. Older versions of Xcode are available to registered users of developer.apple.com
UPDATE: Based on your subsequent comments, I believe I did miss the point of the question and also that you had answered your own question. I think what you are saying is that you upgraded from 10.7 to 10.8, not from 10.6 to 10.8 as I assumed. You also did not make clear in the original question that you were distributing your own version of Apple's libc++ and friends from 10.7 with your own app. Apple does not make it easy in Xcode to do something like that since it has long been Apple's policy to discourage static linking with libs or distributing duplicate libs (which in some cases could violate license terms). There are good reasons for that policy.
The bottom line is that libc++ is only shipped with OS X 10.7 or later systems. There never was Apple support for libc++ in 10.6, so it's misleading to say it was removed. If you want to supply an app that is deployable on 10.6 and later systems and depends on libc++, the safest approach is to build your own clang/llvm and libc++ targeted for OS X 10.6 and use that to build your project. There are various ways to do that, probably the easiest is to use the MacPorts versions and set the deployment target in MacPorts for 10.6. Or build it all from scratch yourself. But modifying the clang compiler within Xcode 4.5 is a bad idea. And copying Apple libraries to one's app is generally a bad idea.
If you have a solution that works for you, great. But I would not recommend it to others.
Normally for my OS X builds I have been compiling my applications on an old Mac Book Pro that runs 10.6. This assures that I support this version of OS X.
However for various reasons, the MBP is no longer a long term option so I have been compiling on a more recent device which runs 10.8. However when I do this, my application does not work on 10.6 even with the -mmacosx-version-min=10.6 flag set. The error that happens when I set the flag is "Symbol not found: _wcsdup" in libSystem.B.dynlib
I looked up this error and the only recommendations I can find is to directly link against the 10.6 SDK. However when I tried copying the 10.6 SDK from my MPB to the new machine (because 10.6 SDK is not installed on 10.8), it fails to compile with errors like "error: bits/c++config.h: No such file or directory" I assume this is because of the way I "installed" the SDK, although others have had success with this.
Does anyone have a solution?
Run 10.6 in a VM, like VMWare or VirtualBox.
I am able to reinstall older SDKs and compilers with this procedure: How can we restore ppc/ppc64 as well as full 10.4/10.5 SDK support to Xcode 4?
You need to change the path of xcode installs in the script.
Also you probably won't be able to use -std=c++11 when targeting 10.6 since you will mostly also need -stdlib=libc++ which is only available when targeting 10.7 or above.
Apple only distributes libc++ binaries since 10.7. You could build your own libc++ and deploy it with your app to 10.6 machines. But Apple hard coded the compiler to disallow -stdlib=libc++ when targeting anything lower than 10.7.
I'm building a C++ command line tool in Xcode. The project contains dylibs for curl, boost and log4cpp.
Ideally id like to build an i386 universal binary that supports 10.4 through to 10.6.
I cant seem to get Xcode to compile, when I target 10.4 it says things like no such file or directory.
When i target 10.6 x_64 it builds ok, but 10.5 i386 complains about my dylibs not being the correct architecture for 10.5?
What version of GCC should i be using?
Also, When i create an install package with PackageMaker, where should the installer place the dylibs that the tool requires?
Many thanks in advance,
Toby.
The 3rd party libraries were built for 10.6 x_64, I needed to rebuild them for 10.4.
I installed the 10.4u sdk by downloading xcode 3.2 and choosing 'install 10.4 support' during the installation process.
After rebuilding each library with GCC 4.0 against the 10.4u sdk, my project compiled successfully.
I also used static libraries so I don't need to include them in the installer.
You should be able to just select the 10.4 SDK and gcc 4.0 and build one executable that will run on anything from 10.4 upwards.
Your libraries are probably only built for X86_64. You need to recompile your libraries as universal binaries.
Edit: Using the 10.4 SDK.
In the Project menu, choose Set Active SDK, and pick Mac OS X 10.4 there.
If you get link errors using that SDK, you probably added libraries which were not build for 10.4
Make sure you're using the 10.4 libraries, e.g. libcurl would be found in
/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/libcurl.dylib
You're probably linking with
/usr/lib/libcurl.dylib
which would be the version for your running OS (I assume 10.6)