Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-Project source code reference in Xcode 4

I know you can have Xcode refer to framework / static lib build targets in other projects, but if the project you want to refer to doesn't have a framework / static lib target, can you directly refer to source code from another Xcode project? I tried to do this using both sub-project and Xcode 4 workspace to no avail. After adjusting the header search path, all the #import statements work correctly, but I'm still getting nasty compiler error repotting symbols not found.

setenv MACOSX_DEPLOYMENT_TARGET 10.7
/Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/Tony/Library/Developer/Xcode/DerivedData/-bewprsseyzwgmsdpwvjfuzjiilap/Build/Products/Debug -F/Users/Tony/Library/Developer/Xcode/DerivedData/-bewprsseyzwgmsdpwvjfuzjiilap/Build/Products/Debug -filelist /Users/Tony/Library/Developer/Xcode/DerivedData/-bewprsseyzwgmsdpwvjfuzjiilap/Build/Intermediates/.build/Debug/.build/Objects-normal/x86_64/.LinkFileList -mmacosx-version-min=10.7 -fobjc-arc -framework Cocoa -o /Users/Tony/Library/Developer/Xcode/DerivedData/-bewprsseyzwgmsdpwvjfuzjiilap/Build/Products/Debug/.app/Contents/MacOS/

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_MagicalRecordHelpers", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_MRCoreDataAction", referenced from:
      objc-class-ref in ItemsArrayController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Also, what's the deal with this new Xcode 4 workspace? And how exactly is it different from sub-projects? The only thing I could find is that they look visually different...

Workspace

enter image description here

Sub-projct

enter image description here

like image 438
Tony Avatar asked Jan 03 '12 09:01

Tony


People also ask

How do I integrate one project to another file in Xcode?

drag and drop xcode file to another xcode file from finder. It will ask you for copy the file then check the check box and it will copy to your project. Save this answer.

How do I add another project as dependency in Xcode?

To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter its repository URL.

How do I add source files to Xcode?

I include them in the project by right-clicking on the project folder in the project view in Xcode, and selecting "Add Files to ...". I then navigate to the folder containing the source files, click on the folder and select "Add." With the options "Create folder references" and "Add to target [target name]".


1 Answers

The answer to the first question is apparently "No Xcode cannot refer to source files in another project". In order to compile a source file (.m files). Xcode project must hold direct references to them. You can go to Target setting -> Build Phases -> Compiled resources to see what will be compiled. Note that unless files are added to the project directly, they will not show up under resources to be compiled. Headers however can be communicated across different projects.

EDIT

And I think the answer to the second question is that whereas Xcode 3 requires always explicit management of dependencies, Xcode 4 workspace allow target dependencies to be managed implicitly, so long as they are all in the same workspace. All that is required to specify dependency is to add a the product of the other project you want to refer to as a linked library in the summary page. These findings took much too long.. (a full productive workday), documentation on this can and should definitely be improved!

like image 172
Tony Avatar answered Sep 28 '22 11:09

Tony