ios - clang : error: linker command failed with exit code 1 (use -v to see invocation) when doing unit test on xcode

标签 ios objective-c xcode unit-testing linker

当我在 xcode 上进行单元测试时遇到此错误。我尝试导入“SignIn.h”并测试 SignIn.h/SignIn.m 中定义的VerifyEmail 类。

我的代码如下:

#import <XCTest/XCTest.h>
#import "SignIn.h"

@interface SignInTests : XCTestCase

@property (nonatomic) VerifyEmail* verifyEmail;

@end

@implementation SignInTests

- (void)testVerifyEmail
{
    _verifyEmail = [[VerifyEmail alloc] init];
}
...

我只是遵循通常的单元测试流程。 import "SignIn.h"和 @property (nonatomic) VerifyEmail* verifyEmail 没问题,但是当我尝试初始化 verifyEmail (_verifyEmail = [[VerifyEmail alloc] init];) 时出现如下错误:

ld: warning: directory not found for option '-Llibs/Debug-iphonesimulator'
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_VerifyEmail", referenced from:
      objc-class-ref in SignInTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我已经为此工作了很长时间,确实需要有人帮助。谢谢!

最佳答案

当尝试向现有 iOS 项目添加单元测试时,有时需要在主应用程序目标的build设置中将“默认隐藏的符号”设置为否。 查看此帖子:http://twobitlabs.com/2011/06/adding-ocunit-to-an-existing-ios-project-with-xcode-4/

它仍然适用于 xcode 7。谢谢 Todd!

关于ios - clang : error: linker command failed with exit code 1 (use -v to see invocation) when doing unit test on xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32079764/

相关文章:

c++ - 使用 C++ 进行 iPhone Quartz 2d 开发?

iphone - 核心数据 bool 属性比较

swift - Cordova错误: Promise rejected with non-error: 'Error code 70 for command:

ios - CALayer 子类 "drawInContext"调用但不绘制?

ios - 链接多对多的对象应该都写在 Realm 中吗?

ios - Swift 中的音频队列服务播放器不调用回调

ios - 是否可以通过深度链接从 Facebook 粉丝页面打开 ios 应用程序?

ios - 如何在 iOS 11 上检测 iPhone/iPad 设备上的总可用/空闲磁盘空间

ios - 为 NSFetchedResultsController 创建关系谓词的正确方法

xcode - 来自链接器的奇怪警告(ld)