Xcode 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18203443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:42:03  来源:igfitidea点击:

Xcode error : linker command failed with exit code 1 (use -v to see invocation)

iosobjective-cxcodeios6xcode4.6

提问by Geek

I am getting an error :

我收到一个错误:

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

Detailed error :

详细错误:

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

I don't have duplicate files in Compile Sources.

我没有重复的文件Compile Sources

Ask if more details is required.

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

EDIT :

编辑 :

#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

Added a path in Library search pathand Header search path. It raised one more error.

Library search path和 中添加了路径Header 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)

采纳答案by Geek

First I needed to set Library search pathand Header search pathas shown in Adding OCMock->step 3in this link.

首先,我需要设置Library search path并如此链接中Header search path所示。Adding OCMock->step 3

After that to solve my Undefined symbolerror, I had to add all classes to test target. To see how to add files to a specific target, look at SO question.

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

回答by Master Stroke

I don't want to drag the comments section as its already reached the limit..I suspect the way you're importing the third party framework such as OCMock is wrong...

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

As you have already downloaded the sample from raywenderlich,just compare its builsettings section with your actual project...

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

Check these link1and link2..Moreover its a possible duplicate of what you're looking for...

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