Communication error while building the unit test target

I have an XCode4 / iOS project with the usual goal and unit test. Everything works fine, except when I try #import one of my classes in my test class and try to use it. If I try to create a unit test target, I get the following link error:

Undefined symbols for architecture i386: "_OBJC_CLASS_$_FRRCategory", referenced from: objc-class-ref in CategoryTests.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status 

In CategoryTests.m, I import the header file as follows:

 #import "../todoro/FRRCategory.h" 

What am I doing wrong?

+52
unit-testing xcode4 linker-errors ocunit
Apr 25 2018-11-21T00:
source share
4 answers

Make sure the FRRCategory source file is added to your compilation sources for your unit test purpose.

Xcode 4:

Project Navigator → "[Project Name]" → In the "Targets" section, select the unit test target → Assembly phases → Deploy compilation sources → Click + at the bottom of the compilation sources and add the correct source file.

+22
Apr 25 2018-11-21T00:
source share

Follow the instructions here . This does not require you to add files to compile sources.

I first skipped that “Characters hidden by default = NO” should be for your application purpose, not for checking purpose.

It worked for me anyway (tm).

+162
Jul 08 2018-11-12T00:
source share

Another problem you can cause is if your unit test uses C functions (or similar) that are not used in a real application.

This may be limited by the presence of a subproject. In my case

  • The app
    • subproject
      • C built-in library (i.e. c and .h files compiled directly inside)

My unit test used several C functions that were not used anywhere, and they were removed from the application binary (NOT from the sub project.a file).

The fix is

  • disable Dead Code Removal for the Debug build application. * and
  • make sure your unit tests use Debug, not Release, in your schema settings.

(* Do not do this with release configurations, as it will inflate the application with code that is never called).

+7
Jul 29. '13 at
source share

You should only reference the folder inside your import if your file is inside the frame. Otherwise, once you have added your file to the project, just do #import "FRRCategory.h" . Well, if you haven’t done something strange using the header search paths.

+1
Apr 25 2018-11-21T00:
source share



All Articles