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.
Related
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.
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.
Has anyone found a fix for this?
I read that it has something to do with new dylib format in Snow Leopard...
(This is the lib I get back from MacPorts.)
Thanks,
rui
What are you trying to use that library with? Chances are you have an old version of some build tool or app. Have you updated all of your MacPorts installation?
sudo port selfupdate
sudo port -u upgrade outdated
EDIT: Based on your additional information, more questions:
You have -I /sw/include and -L /sw/lib which are standard locations for Fink, not MacPorts (/opt/local/{include,lib}). In general, it's not a good idea to mix packages from Fink and MacPorts. Are you actually pulling in anything from Fink? If so, are all the Fink packages up-to-date?
If that doesn't resolve the issue, are you building on 10.5 and, if so, which 10.5? Or are you building on 10.6 an app targeted for 10.5 and 10.6? Make sure you have the latest Xcode in either case.
EDIT: It is very difficult to diagnose problems like this based on sketchy information. You say Leopard in your latest comment but then you say you are using the 10.6 SDK. At this point, all I can suggest is that you make sure you have the latest Xcode updates installed and, if you want more help, update the question with a more complete description of what you are trying to do and exactly how and where you are trying to do it, including versions of tools like gcc, et al. Good luck!
We have this same problem whenever we try to run an executable compiled and linked on Snow Leopard without -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 and then try to run it on Leopard. Note the -isysroot setting is different than in your comment above.
The application was incorrectly built on OS X 10.6 machine for a 10.5 machine. The developer can fix this by considering three things:
Using the correct compiler parameters:
gcc-4.2 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk ...
Using the correct linker settings (setting environment variable before link command). This is required, so that the OS X 10.6 linker will not use the loader command 'LC_DYLD_INFO_ONLY' (=0x80000022), because OS X 10.5 does not understand this command:
export MACOSX_DEPLOYMENT_TARGET=10.5
(or setenv MACOSX_DEPLOYMENT_TARGET=10.5)
After this is fixed, one can check if the application was correctly built for OS X 10.5 by running 'otool':
otool -l binary
The correct binary should not contain any 'LC_DYLD_INFO_ONLY' load commands (only 'LC_DYLD_INFO' commands).
(also see my blog article http://grauonline.de/wordpress/?p=71 )
Is there a small, free C or C++ compiler for OS X, like TCC?
Xcode is not small, or simple like TCC, AFAIK.
I'm looking for something like a GCC binary file or TCC for OS X.
gcc is the most widely used one (and Apple provides official builds of it as part of XCode). XCode is also usually distributed on your OS X cd's, though that version may be a little out of date now, depending on what version of OS X you have.
For information and samples on how to use it, look here.
Look into Fink or one of the similar projects out there if you want a build of gcc that's not linked to Xcode. That said though, Xcode is a great IDE for OS X.
You could use the Xcode Tools that are already included in OSX.
Xcode is the same professional
developer toolset used by Apple to
create Mac OS X, as well as many great
Apple applications, and Xcode is
included with every copy of Mac OS X.
You can use Code::Blocks IDE its simple slick and hav good set of feture, a plus opensurce and ready to dl for 3 major plateforms
still recoment using Xcode if u just have to make projects for MAC, but if u are going to port it to linux and windows, then my choice is Code::Blocks [Give it a try atleast]
I know you want a small compiler, but it is best to just download and install Xcode. It is a great IDE. From there, you don't have to use it if you don't want to. Once it is installed, you can use something like this in terminal:
gcc myFile.c -o myFile
And that would build a source file called myFile.c which contains C code and the output module (executable) would be myFile. You'd execute it by running:
./myFile
Update: What is your reason for not wanting Xcode? Furthermore, is GCC itself ok (disregarding Xcode for a moment)? It's important to know that GCC is not a part of Xcode. Apple made use of GCC, which is an open source C/C++ (and more) compiler.
I just can't find binaries of GCC for mac so downloading Xcode is an easy way to get some...
Update 2: It also just came to my attention that NetBeans will compile C / C++ Code. It also uses the GCC compiler. I'm not sure if it using GCC from my Xcode installation but I thought I'd mention this.
Best Regards,
Frank
There are binary packages for LLVM, both for the Clang and GCC front-ends.
PCC, the Portable C Compiler, is available for the Mac. It is small and free. Its tarball weighs in at total of 1778 KB from its 4th of July CVS Snapshot.
If you don't want to use Xcode install the macports from macports.org and if you like a graphical user interface install porticus as a managment gui for all the installed ports. In Porticus you can now easily install all different versions of gcc without Xcode.
Porticus will compile the packages for your mac and install all the needed dependencies like a Linux packet manager.