20
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

XCTest ターゲットのビルドでリンカーエラー

20
Posted at

昔から開発してゐる iOS 用アプリのビルドターゲットに対して XCTest のビルドターゲットを追加してテストケースを書いたのですが、いざ ⌘U でテストを実行しようとしてみると、リンカーがエラーを吐いて止まってしまひました。

Undefined symbols for architecture x86_64:
"OBJC_CLASS$_Foo", referenced from:
objc-class-ref in FooTest.o
(maybe you meant: OBJC_CLASS$_FooTest)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


どうやらテストケースのコードからテスト対象であるアプリ本体のコードがうまく参照できてゐない様子。
"Build Settings" で "Symbols Hidden by Default" の設定を "No" にしたら直りました。 ![symbolshidden.png](https://qiita-image-store.s3.amazonaws.com/0/38244/07d8e8dd-3fce-9bf4-a4df-0ea1701830c2.png)

アプリ本体のソースコードも XCTest ターゲットの "Target Membership" に加へてしまふという解決策もある様ですが、アプリ本体の各ソースファイルが二重にコンパイル・リンクされることになるのでよろしくないと思はれます。

----

cf. [ios - When do app sources need to be included in test targets? - Stack Overflow](http://stackoverflow.com/q/21911168)
20
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?