OGeek|极客世界-中国程序员成长平台

标题: ios - 运行测试用例时出现 CocoaLumberJack XCTest 链接器错误 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 02:12
标题: ios - 运行测试用例时出现 CocoaLumberJack XCTest 链接器错误

将 CocoaLumberJack 与 XCTest 一起使用时,我收到一个错误,它找不到 DDLog.h。我尝试将其更改为 没有运气。 LumberJack 在 iOS 模拟器中工作时,该项目编译并运行良好,但是当我为单元测试目标运行它时,我收到此错误(请参阅屏幕截图)。

这是我的 -Prefix.pch

  #import <Availability.h>

  #ifndef __IPHONE_5_0
  #warning "This project uses features only available in iOS SDK 5.0 and later."
  #endif

  #ifdef __OBJC__
      #import <UIKit/UIKit.h>
      #import <Foundation/Foundation.h>
      #import <CoreData/CoreData.h>
      #import <CocoaLumberjack/DDLog.h>
      #import "Utilities.h"
  #endif


  #ifdef DEBUG
  static const int ddLogLevel = LOG_LEVEL_VERBOSE;
  #else
  static const int ddLogLevel = LOG_LEVEL_ERROR;
  #endif

错误:

Error

我已将库链接到 tests 目标,如下所示,使用 libPods.a

Linked Libraries

为什么在运行 TestCases 时 LumberJack 不能正确链接?是否需要向 TestTarget 添加其他内容才能正确链接?



Best Answer-推荐答案


我能够通过删除 -Prefix.pch 文件的自定义设置并重新格式化 podfile 以使用目标来解决问题。我不得不移动

 #import "DDLog.h"

#ifdef DEBUG
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
#else
static const int ddLogLevel = LOG_LEVEL_ERROR;
#endif

进入一个“Utility.h”类。

podfile 被重建以链接两个目标:

platform :ios, '7.0'

def common_pods
    pod 'CocoaLumberjack'
    pod 'HexColors'
end

target :MyApp do
    common_pods
end

target :MyAppTests do
    common_pods
end

我还必须从两个目标中删除 libPods.a,因为它不再被构建。而是使用新的 podfile 配置构建 libPods-MyApp.alibPods-MyAppTests.a

关于ios - 运行测试用例时出现 CocoaLumberJack XCTest 链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26021915/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4