stackotter / swift-cross-ui

A cross-platform declarative UI framework, inspired by SwiftUI.
https://stackotter.github.io/swift-cross-ui/documentation/swiftcrossui/
MIT License
651 stars 36 forks source link

Could not build Objective-C module 'CGtk' #47

Closed david-swift closed 1 year ago

david-swift commented 1 year ago

Thank you very much for that great package!

I followed the instructions in the readme for creating a package with an executable target and the swift-cross-ui dependency on macOS 14.0 Beta and Fedora Linux 38. I also tried running the counter example project.

I always get the following error message for #include <gtk/gtk.h in Sources/CGtk/header.h:

'gtk/gtk.h' file not found

Probably because of that error, I get:

Could not build Objective-C module 'CGtk'

On macOS, the warning you may be able to install gtk4 using your system-packager: brew install gtk4 appears. That is exactly the command I have used for installing GTK.

stackotter commented 1 year ago

How weird, what happens if you run gtk4-launch --version?

Three main troubleshooting steps come to mind for this kinda of issue, but they’re pretty generic; swift package clean, if that doesn’t work restart terminal, and if that doesn’t work restart laptop. Hopefully one of those will get swift to correctly detect gtk/gtk.h

david-swift commented 1 year ago

Thank you for the quick response!

I could resolve this problem on macOS by installing pkg-config via brew install pkg-config. The previous error disappeared, but now, there are even more errors appearing when I try to build it:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ffi/module.modulemap:

Redefinition of module 'FFI'

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/dispatch/dispatch.h:

Could not build module 'os_workgroup'

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Versions/A/Headers/CFStream.h:

Could not build module 'Dispatch'

Which results in:

Could not build Objective-C module 'CoreFoundation'

I tried the generic troubleshooting steps, they did not help.

The output of gtk4-launch --version is 4.10.4, but that is not important anymore, right?

david-swift commented 1 year ago

I tried building it again on Fedora, and it worked perfectly, so probably restarting helped in that case. I am still not able to build it on macOS, though.

stackotter commented 1 year ago

I could resolve this problem on macOS by installing pkg-config via brew install pkg-config.

Ah nice, I’ll add that to the instructions. Thanks for figuring that out.

The FFI one is a known issue that I actually faced when building in the GitHub action. Try running the following command to patch the broken file:

sed -i '' 's/-I..includedir.//g' /usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/13/libffi.pc
stackotter commented 1 year ago

I tried building it again on Fedora, and it worked perfectly, so probably restarting helped in that case. I am still not able to build it on macOS, though.

Ok nice, I’ll add that to troubleshooting steps (Im going to add a list of common issues to the documentation; with fixes of course)

david-swift commented 1 year ago

The FFI one is a known issue that I actually faced when building in the GitHub action. Try running the following command to patch the broken file:

sed -i '' 's/-I..includedir.//g' /usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/13/libffi.pc

I executed that command (for me, the path was /opt/homebrew/Library/Homebrew/os/mac/pkgconfig/14/libffi.pc), and after some generic troubleshooting steps (cleaning build folder, restarting, cleaning DerivedData), I was able to run the apps using SwiftCrossUI without running into other problems.

Thank you very much for the help! I'm really looking forward to using a nice SwiftUI-like syntax and Swift for building GTK apps!

stackotter commented 1 year ago

Awesome! Great to hear that you got it working; If you ever make an app with SwiftCrossUI feel free to open an issue to let me know and I can add it to the readme (I'd like to have a list of apps that people can check out). And don't hesitate to let me know if there are any features that are missing that you need for your projects :)

Sherlouk commented 11 months ago

Just in case anybody comes back to this issue in reference to the FFI known issue, if you run pkg-config --libs libffi --debug it gives you the path you need to supply into the sed command in the README.

For me it was /usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.15/libffi.pc.

Running that, removing .build, and then it worked.