realm-swift icon indicating copy to clipboard operation
realm-swift copied to clipboard

Error in linking phase when using Realm as SPM dependency for sub-target

Open aleyooop opened this issue 3 years ago • 9 comments

How frequently does the bug occur?

All the time

Description

Actual result:

  1. Try to archive project with a sub-target that has realm-cocoa as SPM dependency.
  2. Get errors as described here (#7526)
  3. Apply proposed fix to realm-core
  4. Receive another linking error

Expected result: Archive process succeeds

Stacktrace & log output

Undefined symbols for architecture arm64
Symbol: realm::ObjKey realm::Table::find_first<realm::StringData>(realm::ColKey, realm::StringData) const
Referenced from: realm::ObjKey realm::Object::get_for_primary_key_in_migration<objc_object* __strong, RLMAccessorContext>(RLMAccessorContext&, realm::Table const&, realm::Property const&, objc_object* __strong&&) in RLMAccessor.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Can you reproduce the bug?

Yes, always

Reproduction Steps

In description

Version

v10.22.0

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

Any iOS Device (arm64)

Build environment

Xcode version: 13.2 Dependency manager and version: SPM

aleyooop avatar Jan 31 '22 11:01 aleyooop

Hi @aleyooop , I see the pull request in realm-core for that case. I'll ask core team to check it out

pavel-ship-it avatar Jan 31 '22 15:01 pavel-ship-it

@aleyooop I try to reproduce it locally without any luck. Can you share some details on what library you are using in your project? Could you try to clear derived data and/or reset package cache?

pavel-ship-it avatar Jan 31 '22 17:01 pavel-ship-it

@pavel-ship-it This can be easily reproduced with the same reference project in this related issue (#7526)

  1. Build project and get issue with Security framework
  2. Change Realm swift package dependency with fork+applied fixes -> Build fixed
  3. Try to archive

Derived data cleaning and/or resetting package cache don't help.

aleyooop avatar Jan 31 '22 19:01 aleyooop

Same issue with missing symbols

vladyslavpopovych avatar Feb 11 '22 19:02 vladyslavpopovych

It seems like linking a sub-dependency is not possible with the current configuration of the Sample project provided. You need to add them as Package.swift modules so it links correctly any sub-dependency (In this case is RealmCore). I updated the Sample project which I used to test archiving the App, and it is working. The missing Security framework should be fixed by this PR. Let me know if you have any question.

dianaafanador3 avatar Mar 17 '22 00:03 dianaafanador3

Hi,

Same issues here.

I have some internal framework which is dependent to Realm. I added Realm and RealmSwift from SPM. No issues on building but have an error on archive side.

Undefined symbols for architecture arm64: "realm::ObjKey realm::Table::find_firstrealm::StringData(realm::ColKey, realm::StringData) const", referenced from: realm::ObjKey realm::Object::get_for_primary_key_in_migration<objc_object* __strong, RLMAccessorContext>(RLMAccessorContext&, realm::Table const&, realm::Property const&, objc_object* __strong&&) in RLMAccessor.o ld: symbol(s) not found for architecture arm64

emrekarasahin avatar Apr 13 '22 13:04 emrekarasahin

Hello, we are also having the same issue.

@emrekarasahin You can apply the changes found in PR5204 in realm-core to SourcePackages/checkouts/realm-core/src/realm/table.cpp (located in your DerivedData folder for your project) as a work around until that PR is merged.

nojoDOTse avatar Apr 13 '22 14:04 nojoDOTse

Hello, is there any update in this?

igrechuhin avatar May 05 '22 20:05 igrechuhin

Any suggestions?

RustamKhisamov avatar Jul 15 '22 09:07 RustamKhisamov