Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
397 views
in Technique[技术] by (71.8m points)

objective c - Is it possible to compile a newer version of LLVM and use it with Xcode?

I have an old computer that cannot upgrade to Lion, but I would like to use it for coding while still taking advantage of syntax such as instancetype and Objective-C literals. Has anyone tried to compile a newer Clang and LLVM to use with an older Xcode and been successful?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are various ways to use the newest LLVM/Clang version.

(1) Plugins, as described in the comments above, e.g.: http://blog.wadetregaskis.com/tot-clang-llvm-in-xcode/

As pointed out in the linked blog post, you may get errors/warnings from Xcode's real-time syntax checking as Xcode uses an older version of libclang (more on that under (3)). It is likely to compile fine, but editing source code won't be a lot of fun.

(2) Set the compiler via the CC flag. This is probably the easiest/fastest solution and the setting only affects one project. Go to the project's Build Settings, choose "Add Build Setting" -> "Add User-Defined Setting" (in Xcode 5, this is hidden in the Editor menu), name it CC and set the value to the path of your version of Clang. Worked fine for me, but as with (1), you might get conflicts with the live error reporting, especially if you want to use new syntax such as literals, or pass flags for warnings that the older version does not understand.

(3) Replace the compiler. Make sure you back up any files before replacing them. There are two files that need to be replaced: the Clang binary, and libclang.dylib. Go to /Applications/Xcode.app/ -> Option-Click -> "Show Package Contents" -> /Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr. clang is in /bin, libclang.dylib is in /lib.

Both binaries can either be compiled from source (which will give you an even newer version, of course) or just copied from the latest Xcode package. I ran into trouble using a customised version of libclang, but I suspect the problem originates from my modifications there. If in doubt, use libclang from a later Xcode version.

Note: My modified libclang binary used ARC and is therefore incompatible with Xcode 4 which runs with garbage collection. Xcode 5 itself uses ARC so the problem has vanished. If you compile libclang unmodified, you shouldn't come across the issue in either Xcode 4 or 5.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...