How do I execute a command-line application built with Xcode? - xcode6

I'm building a small command-line utility (not an app) with xcode. All I want to do is the equivalent of a gcc -o name, and I'm completely stumped. I can compile just fine in xcode, and execute the result inside of xcode, but I can't for the life of me find the executable image anywhere on the disk. There's nothing at all executable in the .../DerivedData folder, for example. How do I tell Xcode to create a stand-alone executable image (that I can launch from a Terminal window) and put it in a known location?

Found the answer. When you select the Product for the application, make sure that the application is set to Unix Executable (it defaults to something else). The full path to the product is displayed further down in the dialog.

Related

How can I run an embedded binary in my OSX application?

I have an application which needs to run an external program.
I have included this program as an Embedded Framework. When archived, it appears at the location %AppRoot%/Contents/Frameworks/MyExternalApplication.
How can I run this program from my app's code without using an absolute path? I'd like to run in both release and debug.
Thank You!
You can run the executable by using an NSTask object or the posix_spawn() function.
You can use the NSBundle class to find the absolute path of the executable. See this article for details.
Notes:
That is not the correct place within the app bundle to place the executable; I believe it should be in Contents/MacOS, as documented here.
If the main app is sandboxed (a requirement if you want to put the app on the Mac App Store) then an entitlement is required that will be embedded into the external executable so that it inherits the app's sandbox. See this question for details.
Once you've done 2. you will notice that the executable will no longer run from the command line, but that's nothing to worry about, as it will run from within your app.

Xcode: how to build a static library project correctly?

This question will be easy for Xcode pros but for a MonoTouch developer it seems to be impossible to resolve. :-)
I'm using Xcode 4.5 and I want to target iOS 5.1 and above and iOS Simulator 5.1 and above.
I have a a library project here and it is coming with a prebuilt binary named "DemoLib" (no extension and it is 11MB in size). The library is a fat lib for Simulator and iOS 5.1+.
I can use that library without any problem.
However if I try to build the library myself, I end up with a "DemoLib.a" file (notice the extension and the size of 30MB). How can I get the same build result? What is a .a file compared to the file without extension?
I tried to build the project "for running", and "for archiving" in Xcode. Both results in the same 30MB .a file.
I was expecting some dropdown in Xcode where one could select "DEBUG" or "RELEASE" build and the latter one would create the smaller lib.
Of course I could never tell without seeing the framework's project file. Having said that, there is an excellent guide to creating and compiling iOS frameworks here: https://github.com/jverkoey/iOS-Framework
Using the above guide, you should be able to recreate your framework's project from scratch, add the files you have to it, and properly compile it.
Hope this helps! :)
Did it come with a Makefile? Create a new target, set the build settings of the target to what's in the Makefile, then set your project to depend on that new target.
A file with the .a is a static library, which means it depends on nothing external and all the code it needs is compiled inside it. I think no extension generally implies dynamic library, which means it'll depend on some dependencies being present on your system to link against. Maybe that's why the .a is so much bigger. I think Xcode will build static by default because iOS does not allow the use of dynamic libraries.
The dropdown for what to build is in your scheme. Command+shift+< to view your scheme. Within the scheme you can edit which environment each method of building will use.

bundle dylib with application

I'm running Xcode 4.5 and MacOS 10.7.4 and trying to create a MacOS app for local distribution.
I have a dylib from a 3rd party USB hardware vendor. Rather than drop this into /usr/lib, I wanted to bundle this with the app. I have tried all of the methods mentioned here that I could find:
Creating a Cocoa Library target, and using a copy build phase, setting paths with #rpath and #executable_path and #loader_path ...
Here's what I ran into:
I can get the target app to build to compile and run if the dylib is copied into the same directory as the target app (by setting destination to "Products Directory"), however this only works while the app is running within Xcode. If I run the app from the finder it still looks for the dylib at /usr/lib.
A caveat when changing the destination setting: any files copied to a location in the previous build are not deleted when you make a change a build again. This tricked me into thinking a few times that I had a solution when I didn't.
"Library search paths" appears to work as expected when linking, but setting "Dynamic Library Install Name" and "Runpath search paths" don't appear to stop the code from looking in /usr/lib only at run time. They don't seem to have any effect at all.
So, why would setting those path variables have no effect, and how can I set the run time search path?

Mac server in order to compile obj-c projects?

Is it possible to write an obj-C code with any text editor and then upload it to Mac server to compile it using Xcode??
I know that it is possible to compile your project using Xcode without open it something like use some command lines, but I am not sure is it possible to make it a server and then upload any obj-c code!
You can compile your projects from the command line using the xcodebuild command. Automating your builds is another story altogether: you'll need to set up your server to download the updated source code (typically via version control, e.g. svn update or p4 sync), do the build, and then upload the builds results somehwere (e.g. check into version control).
Doing this is non-trivial, and there's a lot of software out there, such as FinalBuilder, to help make this easier, although FinalBuilder is Windows software so probably isn't what you want.

compiling Objective-C program on Windows

A friend sent me 4 files (two .m files, one .pch file, and one .h file) that he says compile together into an Objective-C program. From what I understand, it's an Apple language, and I use Windows. I've been trying to compile it in a new project on Dev-C++, but haven't had any luck. After some research, I downloaded a special Objective-C library for it and selected "Yes" under "Link an Objective C program," but am getting a build error when I try to compile it.
The code uses Cocoa, but according to my friend, it will work the same in Windows if I import Foundation.h instead of Cocoa.h. I found a tutorial on how to compile Objective-C programs in Windows here, but I don't understand step 2 (which is "Set environment variable for GCC compiler (C:\GNUstep\mingw\bin\gcc.exe)") since that file doesn't exist on my computer. When I follow the compilation instructions, I get this error: sh: gcc: command not found. If possible, I'd rather compile it in a GUI-based compiler, as I hate working with command prompts.
Any help with compiling these files on any program is greatly appreciated!
Time to cowboy up, and learn some command line compiling.
First, you need to install the GNUStep on your machine.
Then, set the appropriate environment variable to point to whereever you installed GNUStep to.
Now you should be able to finish the tutorial.
GNUStep is designed to let developers build cocoa applications on a variety of platforms.
Environment variables are named strings that exist for all processes in Windows. If you open a cmd window and enter the command SET you will see a list of all the currently defined environment variables.
On Windows XP, add a new one by right clicking My Computer and selecting properties. Then hit the advanced tab and click on the environment variables button at the bottom. You can either add the variable for just you or for all users on the system.
I don't know how to set environment variables for later versions of Windows but I expect Google might have some useful links.
From some of your comments, it is clear you haven't installed GNUStep in the same place as the instructions. Just do a file search for gcc.exe to find out where you have installed it.