简体   繁体   中英

How can I get Xcode 4.4.1 with OCMock + OCUnit to recognize my project's header files?

I followed these steps: http://ocmock.org

and also these: http://twobitlabs.com/2011/06/adding-ocunit-to-an-existing-ios-project-with-xcode-4/

Though I could not successfully get step #4 of the twobitlabs instructions to work. meaining "Click the Build Settings tab and set the Bundle Loader setting to$(BUILT_PRODUCTS_DIR)/MyExistingApp.app/MyExistingApp"... When I did that, I get:

Ld /Users/patrick/Library/Developer/Xcode/DerivedData/Notes_and_Clefs-fpzvpdfkkkjuynefaqeajfdiznbp/Build/Products/Debug-iphonesimulator/UnitTests.octest/UnitTests normal i386
cd "/Users/patrick/coding/objective_c/vms/Notes and Clefs"
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -bundle -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -L/Users/patrick/Library/Developer/Xcode/DerivedData/Notes_and_Clefs-fpzvpdfkkkjuynefaqeajfdiznbp/Build/Products/Debug-iphonesimulator "-L/Users/patrick/coding/objective_c/vms/Notes and Clefs/usr/lib" -F/Users/patrick/Library/Developer/Xcode/DerivedData/Notes_and_Clefs-fpzvpdfkkkjuynefaqeajfdiznbp/Build/Products/Debug-iphonesimulator -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/Developer/Library/Frameworks -F/Applications/Xcode.app/Contents/Developer/Library/Frameworks -filelist "/Users/patrick/Library/Developer/Xcode/DerivedData/Notes_and_Clefs-fpzvpdfkkkjuynefaqeajfdiznbp/Build/Intermediates/Notes and Clefs.build/Debug-iphonesimulator/UnitTests.build/Objects-normal/i386/UnitTests.LinkFileList" -mmacosx-version-min=10.6 -bundle_loader "\"/Users/patrick/Library/Developer/Xcode/DerivedData/Notes_and_Clefs-fpzvpdfkkkjuynefaqeajfdiznbp/Build/Products/Debug-iphonesimulator/Notes\\ and\\ Clefs.app/Notes\\ and\\ Clefs\"" -Xlinker -objc_abi_version -Xlinker 2 -force_load "/Users/patrick/coding/objective_c/vms/Notes and Clefs/usr/lib/libOCMock.a" -ObjC -fobjc-link-runtime -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50100 -lOCMock -framework SenTestingKit -framework UIKit -framework Foundation -o /Users/patrick/Library/Developer/Xcode/DerivedData/Notes_and_Clefs-fpzvpdfkkkjuynefaqeajfdiznbp/Build/Products/Debug-iphonesimulator/UnitTests.octest/UnitTests

ld: file not found: "/Users/patrick/Library/Developer/Xcode/DerivedData/Notes_and_Clefs-fpzvpdfkkkjuynefaqeajfdiznbp/Build/Products/Debug-iphonesimulator/Notes\ and\ Clefs.app/Notes\ and\ Clefs"
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Yet, when I copy/paste that path in my terminal, it definitely is there.. as you can see here:

>ls -l /Users/patrick/Library/Developer/Xcode/DerivedData/Notes_and_Clefs-fpzvpdfkkkjuynefaqeajfdiznbp/Build/Products/Debug-iphonesimulator/Notes\ and\ Clefs.app/Notes\ and\ Clefs
-rwxr-xr-x  1 patrick  staff  1862424 Aug 15 22:42 /Users/patrick/Library/Developer/Xcode/DerivedData/Notes_and_Clefs-fpzvpdfkkkjuynefaqeajfdiznbp/Build/Products/Debug-iphonesimulator/Notes and Clefs.app/Notes and Clefs

So, I don't know if it's a problem with my file having spaces in it or not...

If I skip that step, when I run my tests, I get the infamous error:

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

Where the test.m file doesn't seem to understand what the header is for the actual class I am testing, despite my #import "Question.h" in the test.h's header... (also, adding it directly to the .m does nothing).

It occurred to me when closely looking at the stack trace.. ".../Debug-iphonesimulator/Notes\\ and\\ Clefs.app/Notes\\ and\\ Clefs\\""

the \\'s can't be good! I changed the Bundle Loader to the path without the backslashes, and now it works! Hooray!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM