SwiftKafka icon indicating copy to clipboard operation
SwiftKafka copied to clipboard

Using SwiftKafka for watchOS

Open MFabi23 opened this issue 5 years ago • 2 comments

I am developing a watchOS app, that uses data coming from a Kafkastream and I want to use this library for this purpose, but it keeps ignoring my local "librdkafka" library.

Detailed error description:

  • Warnings:
  1. ignoring file /usr/local/Cellar/librdkafka/1.3.0/lib/librdkafka.dylib, building for watchOS-arm64_32 but attempting to link with file built for macOS-x86_64
  • Errors: Undefined symbol: _rd_kafka_produce Undefined symbol: _rd_kafka_poll Undefined symbol: _rd_kafka_conf_dump Undefined symbol: _rd_kafka_topic_name Undefined symbol: _rd_kafka_consumer_close Undefined symbol: _rd_kafka_consumer_poll Undefined symbol: _rd_kafka_flush Undefined symbol: _rd_kafka_brokers_add Undefined symbol: _rd_kafka_commit Undefined symbol: _rd_kafka_topic_partition_list_new Undefined symbol: _rd_kafka_topic_partition_list_destroy Undefined symbol: _rd_kafka_message_destroy Undefined symbol: _rd_kafka_topic_new Undefined symbol: _rd_kafka_topic_partition_list_add Undefined symbol: _rd_kafka_subscribe Undefined symbol: _rd_kafka_conf_set_dr_msg_cb Undefined symbol: _rd_kafka_conf_set Undefined symbol: _rd_kafka_conf_dup Undefined symbol: _rd_kafka_conf_new Undefined symbol: _rd_kafka_conf_destroy Undefined symbol: _rd_kafka_conf_dump_free Undefined symbol: _rd_kafka_poll_set_consumer Undefined symbol: _rd_kafka_topic_destroy Undefined symbol: _rd_kafka_assign Undefined symbol: _rd_kafka_new Undefined symbol: _rd_kafka_destroy

What I did:

  1. Installed librdkafka
  • brew install librdkafka
  1. Created app
  • Created a new watchOS standalone app in Xcode
  • Added a new SwiftPackage with the built-in SPM from Xcode using the URL from your GitHub SwiftKafka project
  • Added SwiftKafka to "Link Binary With Libraries" in my WatchKit Extension
  1. Build the App -> Build failed with above errors

MFabi23 avatar Feb 28 '20 12:02 MFabi23

I tried with the AppleWatch simulators and a real AppleWatch Series 4 as target device.

MFabi23 avatar Feb 28 '20 12:02 MFabi23

To compile librdkafka with Xcode, do these two things:

  1. brew install librdkafka
  2. add this to the target section of your Package.swift:
linkerSettings: [
    .unsafeFlags(["-Xlinker", "-L/usr/local/lib"], .when(platforms: [.macOS]))
]

I know this comment is old but I just finally figured this out and I'm overjoyed to share!

source: https://github.com/Kitura/SwiftKafka/issues/11#issuecomment-947528301

winsmith avatar Feb 03 '22 19:02 winsmith