【问题标题】:Xcode error : linker command failed with exit code 1 (use -v to see invocation)Xcode 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
【发布时间】:2013-08-13 07:48:21
【问题描述】:

我收到一个错误:

ld: library not found for -lOCMock
clang: error: linker command failed with exit code 1 (use -v to see invocation)

详细错误:

Ld /Users/akashpatel/Library/Developer/Xcode/DerivedData/RideShareBuddy-cqfdiphwubeiexdigypzpjjfqaiy/Build/Products/Debug-iphonesimulator/RideShareBuddyTests.app/RideShareBuddyTests normal i386
cd "/Users/akashpatel/Documents/iOS development/RideShare/RideShare"
setenv IPHONEOS_DEPLOYMENT_TARGET 6.1
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 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk -L/Users/akashpatel/Library/Developer/Xcode/DerivedData/RideShareBuddy-cqfdiphwubeiexdigypzpjjfqaiy/Build/Products/Debug-iphonesimulator "-L/Users/akashpatel/Documents/iOS development/RideShare/RideShare/RideShare" -F/Users/akashpatel/Library/Developer/Xcode/DerivedData/RideShareBuddy-cqfdiphwubeiexdigypzpjjfqaiy/Build/Products/Debug-iphonesimulator "-F/Users/akashpatel/Documents/iOS development/RideShare/RideShare" -filelist /Users/akashpatel/Library/Developer/Xcode/DerivedData/RideShareBuddy-cqfdiphwubeiexdigypzpjjfqaiy/Build/Intermediates/RideShareBuddy.build/Debug-iphonesimulator/RideShareBuddyTests.build/Objects-normal/i386/RideShareBuddyTests.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -ObjC -all_load -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=6.1 -framework QuartzCore -framework GHUnitIOS -framework UIKit -framework Foundation -framework CoreGraphics -lOCMock -o /Users/akashpatel/Library/Developer/Xcode/DerivedData/RideShareBuddy-cqfdiphwubeiexdigypzpjjfqaiy/Build/Products/Debug-iphonesimulator/RideShareBuddyTests.app/RideShareBuddyTests

我在Compile Sources 中没有重复文件。

询问是否需要更多详细信息。

编辑:

#import <GHUnitIOS/GHUnit.h>
#import "OCMock.h"
#import "RS_LoginRSViewController.h"

@interface RS_LoginRSViewControllerTest : GHTestCase
{
    RS_LoginRSViewController * loginObject;
}
@end

@implementation RS_LoginRSViewControllerTest

// Run before each test method
- (void)setUp { }

// Run after each test method
- (void)tearDown { }

// Run before the tests are run for this class
- (void)setUpClass
{
    loginObject = [[RS_LoginRSViewController alloc] init];
    GHAssertNotNil(loginObject, @"Could not create test object.");
}

// Run before the tests are run for this class
- (void)tearDownClass { }

- (void)testViewDidLoad
{
    GHTestLog(@"Log with a test with the GHTestLog(...) for test specific logging.");
}

@end

Library search pathHeader search path 中添加了一个路径。它又引发了一个错误。

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_RS_LoginRSViewController", referenced from:
      objc-class-ref in RS_LoginRSViewControllerTest.o
     (maybe you meant: _OBJC_CLASS_$_RS_LoginRSViewControllerTest)

【问题讨论】:

  • 您是否正确添加了所有必需的框架?..您是否添加了 libz.dylib?
  • 我刚刚集成了 GHUnit 和 OCMock。刚开始第一堂考试。遵循raywenderlich.com/3716/… 上的所有步骤。我在集成 OCMock 时遇到了一个问题,#import &lt;OCMock/OCMock.h&gt; 给出了错误。我将其更改为 #import "OCMock.h" 并且错误消失了。我不知道这是否会导致问题。
  • 我怀疑是一样的,看起来你缺少一个关键框架。
  • @khanh.tran.vinh 我已经添加了框架。可能是其他问题。
  • 如果有任何问题,我将发布单元测试代码。

标签: ios objective-c xcode ios6 xcode4.6


【解决方案1】:

我不想拖动 cmets 部分,因为它已经达到了限制。我怀疑您导入第三方框架(如 OCMock)的方式是错误的...

由于您已经从raywenderlich 下载了示例,只需将其 builsettings 部分与您的实际项目进行比较...

检查这些link1link2..此外,它可能与您正在寻找的内容重复...

【讨论】:

  • 又一个更新。使用这个ocmock.org/ios 我修改了Other Linker Flags 并删除了未定义符号的错误。目前我面临的唯一错误是ld: file not found: -fobjc-arc clang: error: linker command failed with exit code 1 (use -v to see invocation)
  • 正如他所说,我在目标中添加了RS_LoginRSViewController.m 文件以进行测试。但同样的问题。
【解决方案2】:

首先我需要设置Library search pathHeader search path,如Adding OCMock-&gt;step 3 中的link 所示。

在那之后为了解决我的Undefined symbol 错误,我不得不将所有类添加到测试目标。要了解如何将文件添加到特定目标,请查看 SO question

【讨论】:

    猜你喜欢
    • 2019-09-28
    • 2023-03-30
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 2016-01-04
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多