views:

2089

answers:

2

I'm trying to build for multiple targets in Xcode, to simplify the process of creating a "lite" and "pro" version of my application. In theory, this is great and I can pass defines to GCC_PREPROCESSOR_DEFINITIONS for use in my code. However, I'm having problems actually getting it to work due to an error trying to launch the second target in the simulator: Failed to launch simulated application: Unknown error.

Here is the simple process I'm using to create the additional target:

  1. Add #ifdef MYAPP_PRO to source files to modify behavior based on pro/lite version of app (and verify application is working as expected)
  2. Select Project > New Target... from menu, and pick "Cocoa Touch Application" (named MyAppPro")
  3. Edit new target settings; add GCC_PREPROCESSOR_DEFINITIONS user-defined setting and set the value to "MYAPP_PRO" (no quotes)
  4. Set active target to "MyAppPro"; build and run.
  5. Failed to launch simulated application: Unknown error.
  6. Copy all settings from Info.plist to MyAppPro-Info.plist and try again
  7. Failed to launch simulated application: Unknown error.

The build completes just fine, but I'm unable to run in simulator.

Editing the project.pbxproj in the .xcodeproj directory, I notice there are some key differences between the two target definitions' build settings. I tried manually editing the file but must have done something wrong because I couldn't get it to load in Xcode afterwards.

Original target's "Debug" build settings:

  buildSettings = {
   ALWAYS_SEARCH_USER_PATHS = YES;
   ARCHS = "$(ARCHS_STANDARD_32_BIT)";
   "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
   GCC_C_LANGUAGE_STANDARD = c99;
   GCC_WARN_ABOUT_RETURN_TYPE = YES;
   GCC_WARN_UNUSED_VARIABLE = YES;
   ONLY_ACTIVE_ARCH = YES;
   PREBINDING = NO;
   SDKROOT = iphoneos2.2.1;
  };

Thew new MyAppPro target's "Debug" build settings:

  buildSettings = {
   ALWAYS_SEARCH_USER_PATHS = NO;
   CODE_SIGN_IDENTITY = "iPhone Developer";
   COPY_PHASE_STRIP = NO;
   GCC_DYNAMIC_NO_PIC = NO;
   GCC_OPTIMIZATION_LEVEL = 0;
   GCC_PRECOMPILE_PREFIX_HEADER = YES;
   GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/UIKit.framework/Headers/UIKit.h";
   INFOPLIST_FILE = "MyAppPro-Info.plist";
   INSTALL_PATH = "$(HOME)/Applications";
   OTHER_LDFLAGS = (
    "-framework",
    Foundation,
    "-framework",
    UIKit,
   );
   PREBINDING = NO;
   PRODUCT_NAME = MyAppPro;
   SDKROOT = iphoneos2.2.1;
  };
+3  A: 

You didn't say whether you actually ever added source files to the target. A new target (unlike a new project) has no source file templates; you have to add them yourself. So the Simulator might be telling you "you built successfully, but there's nothing to run."

cdespinosa
You are correct. I'm not sure how to add source files to a target, but duplicating the existing target and adjusting the name / settings worked perfectly. Thanks!
pix0r
A: 

How did you managed to get this working exactly? Thanks.

The problem was that my source files were not assigned to the proper targets. If you get info on a file in your project, under "Targets" there are checkboxes for each available target. I just had to make sure all of my files were "included" in the proper targets.
pix0r