onekiloparsec / SwiftAA

The most comprehensive collection of accurate astronomical algorithms in (C++, Objective-C and) Swift.
http://www.onekiloparsec.dev/
MIT License
171 stars 31 forks source link

Failed to build for SwiftUI preview #88

Closed Saturnyn closed 4 years ago

Saturnyn commented 4 years ago

Hello,

when I add the SwiftAA lib to my SwiftUI app, the live canvas preview fails to build:

symbol(s) not found for architecture x86_64

Here is the full error log: build-error-swift-UI.txt

From what I understand, it looks like the ObjcAA framework is not built for x86_64 which the SwiftUI preview uses.

Did anyone run into the same problem ? Since I am new to iOS development and struggled to just get the lib to work in a normal build, it is quite possible that I misconfigured something, so any advice would be appreciated :)

Thanks

Edit: forgot to mention the lib was added in Xcode via the Swift Package Manager (full disclosure: tried with Carthage but got another kind of error at runtime)

onekiloparsec commented 4 years ago

Hi. I struggled quite a lot to make the project work with all packaging managers. But I haven't tried to setup a SwiftUI setup (simply because I had no real time to try it). But I'll try!

onekiloparsec commented 4 years ago

I've made some progresses. There were 2 problems:

Could you give a try and let me know you have a new error ? (something related to NSObject)?

This isn't yet working, but I'm fighting this NSObject error now.

onekiloparsec commented 4 years ago

Hm, there is something I don't get. When adding only SwiftAA as dependency of my SwiftUI project, everything compiles fine and it runs on simulator. The problem occurs only when one includes ObjCAA. Please, could you try by specifying only SwiftAA and see how it goes ? (it seems to work both with master branch and existing 2.2.2 release).

Screenshot 2020-02-01 at 10 56 06
Saturnyn commented 4 years ago

Hi, thanks for following up on this.

When I used Swift Package Manager to add SwiftAA, I only selected "SwiftAA", so it is already the only one I have in my Framework list (the project does compile and run fine like this, my only problem is with the SwiftUI preview).

I tried switching to the master branch and tried with and without "AAplus". I got the same error in the preview in both cases. The error log did change a little compared to what I had previously so I'm sending the new one: build-error-swift-UI-2.txt

Just to make sure we are trying the same thing, the preview I have a problem with is activated like this:

Screenshot 2020-02-03 at 11 19 17

And the error looks like this: Screenshot 2020-02-03 at 11 07 20

I think it is a fairly recent addition to XCode and it requires macOS Catalina to run, so maybe we do not get the same result because we are on different versions of XCode ? I am using the latest I think (Version 11.3.1 (11C504))

onekiloparsec commented 4 years ago

Wonderful, with screenshots. Will check as soon as I can (very busy during the week). I'm also on Catalina.

sbenitezb commented 4 years ago

I’m experiencing the same issue. For some reason Xcode is unable to link against a dynamic library with objc runtime when previewing SwiftUI views. Makes working with SwiftUI difficult because one of the premises of SwiftUI is you write code which you can instantly preview without running your app.

Setting the ObjCAA product’s type to .static solves the issue. As SwiftAA is being statically linked with both ObjCAA and AAplus for whatever reason even when both libraries are set dynamic, then this setting doesn’t change the resulting product.

onekiloparsec commented 4 years ago

Really sorry for having let the time flew on this issue... Just overwhelmed with day job. Would you mind making a PR ? I'd be happy to merge rapidly.

sbenitezb commented 4 years ago

Sure, no problem. I’m still baffled it’s not building all libraries as dynamic as it should. I would prefer no to link SwiftAA dependencies statically, so I’ll keep looking for a better solution to solve the issue. If I don’t find one, I’ll make a PR.

onekiloparsec commented 4 years ago

v2.2.5 available. @sbenitezb @Saturnyn If you build something with SwiftAA, I'd be happy to include it in the list of apps using it in the README.