I'm running latest TextMate 1.5 (on OSX Lion) and have the latest XCode 4.3 installed.
I'm sort of taking the low road when learning Objective-C by bypassing XCode for start and doing plain samples and exercises using TextMate and command line. When hitting Cmd-R in TextMate the (console) something builds and runs typed Objective-C console program. However, it doesn't compile things that it should (from my POV) compile, since compiling them from command line with clang works fine. When I switch to building from command line I see that those same things fail when I use gcc instead of clang.
My question is - how do I convince TextMate to use clang instead of gcc when I hit Cmd-R for Objective-C (.m) source files?
(I waded through bundle settings but to no avail, googled it, etc. So it must be either something dead simple that I'm missing or nobody ever wanted to go that way. I'm assuming the first.)
P.S. I converted from Windows some weeks ago so don't assume that I'm an expert Mac user.
Here is a way to do this:
Bundles > Bundle Editor > Show Bundle Editor
Expand 'C'
Select 'Run' command
Replace 'GCC' with 'CLANG' in the when "objc" case (it is the g variable)
Related
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?
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.
I have a C++11 codebase I compile with gcc 4.6 from MacPorts on OS X Lion. I also need to compile and link some OS-specific Objective C/C++ files to make the final executable. I would like to use the same compiler version to compile the whole project, but I cannot get the MacPorts version 4.6 of gcc to recognize Objective-C files; it always attempts to interpret them as C++ code and ignores the .mm file extension. (Compiling these files does work with the Xcode version of gcc, just not the MacPorts one. However that gcc is version 4.2 and I want to compile everything with gcc 4.6 or later.)
Forget IDE's or build tools: I get the same result from a commandline invocation of the compiler. That is, I record a commandline that works for compiling .mm files with the Apple gcc, verify yes it does work from the commandline, then run the identical command with nothing changed but the compiler used and it doesn't work. What am I missing?
It appears maybe the specific problem I'm having might be due to an Apple specific language extension, as the specific error I get is the same as this quote from a blog post:
After adding this, I was good for about 30 seconds until I get to the
portion of my project where some COCOA Objective-C UI stuff was being
compiled.
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSTask.h:75:24:
error: expected unqualified-id before '^' token
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSTask.h:75:24:
error: expected ')' before '^' token
Uh oh. I know what this is. This is the Apple "blocks" language
extension. It appears that blocks are used in a bunch of the system
header files. I don't think there is going to be a way to get around
this using MacPorts gcc. The FSF gcc just doesn’t know about blocks.
Fortunately for me, I didn't have anything in the Objective C/C++ code
that needed to be compiled with gcc 4.6 so I just had this target
compile using clang.
I wonder if it is possible to make an Objective-C project (no UI, no simulator is needed, hosted on Github) to be built on Travis?
Current Travis docs seems not to contain any information regarding the option to have Objective-C projects built on Travis.
But Building a C Project says that:
Travis VMs are 32 bit and currently provide
gcc 4.6
clang 3.1
core GNU build toolchain (autotools, make), cmake, scons
and that default test script is run like
./configure && make && make test
So, to rephrase the subject question:
Do any workarounds exist to make SenTestingKit test suite, that my project currently uses, behave like a C test suite, so it could be treated as such by Travis VM?
NOTE 1: Here is the list of resources, which seem to be related to the question:
Compiling Objective-C without a GUI. It claims that Both gcc and clang compile Objective-C 2.0 and that sounds very promising!
NOTE 2: I suspect that it is possible to use some testing tool other than SenTestingKit:
this tool should be easy to be run without a GUI and without xcodebuild etc: I've opened related issue for that: Is there any non-Xcode-based command line testing tool for Objective-C?. I am even thinking about writing an easy one just to be used by my project.
A few days Travis announced that they are now also supporting objetive-c projects. See Building An Objective-C Project for more info.
Update
It is even possible to make Travis launch the simulator so that you can run application tests and UI related stuff. I required a little extra work, but it's pretty straight forward. I wrote about it here.
I've been tearing my hair out over this, and Google hasn't yielded much so my problem must be caused by my own specific brand of stupidity.
Basically, having installed Xcode 4 I removed the /Developer-old folder (properly, can't remember the command but I used the uninstall script rather than sticking it in the trash).
Xcode builds projects fine, and the latest version of all the Objective-C frameworks seem to live in /System/Library/Frameworks, but when I compile something (which built fine in the Xcode 3 days) clang complains that it can't find any headers, e.g:
fatal error: 'Cocoa/Cocoa.h' file not found
I've tried forcing the framework search path with -F to no avail- is there a common underlying issue or have I just screwed my machine?
Reinstall the developer tools. It will take a lot less time than tracking down whatever you broke.
I'm currently trying to get g++ working, and looking at http://gcc.gnu.org/install/build.html, I can't seem to find where it says how "to perform a 3-stage bootstrap of the compiler". Where would I find this information?
(I'm on a mac, in case that matters.)
After running configure, you do make bootstrap
You cannot bootstrap GCC without an already-functioning compiler on your platform:
From the prerequisites page:
ISO C90 compiler
Necessary to bootstrap GCC, although versions of GCC prior to 3.4 also allow bootstrapping with a traditional (K&R) C compiler.
And to preempt your next question, you also need a functioning compiler (usually GCC) in order to build Clang+LLVM.
It might be possible to do what you're trying so hard to do, by cross-compiling GCC from some other platform (see this section of the documentation). But I imagine this is not for the feint of heart, and you'd be far, far better off simply updating your copy of Mac OS X to the latest version with Xcode support.
From that link:
For a native build, the default configuration is to perform a 3-stage bootstrap of the compiler when `make' is invoked.
It seems to me that if your configuration isn't tweaked, it should do it out of the box. Just type make.
More specifically, you have to download the source code, and follow the instructions in that whole tutorial in order to build.
A side note - I am finding it hard to believe that there is no easy way to get GCC on an OSX box without having the installation media. That sounds really annoying :)
Edit:
If you are simply trying to write C++ on OSX, you could install one of many other IDEs. If you are lucky, they may come with their own compiler. Here is a list of alternatives to XCode:
http://alternativeto.net/desktop/xcode/?profile=mac&platform=mac