Skip to content

Using an external library (in my case, librdkafka) #137

Open

Description

@MMahdiSetak

Hi
I've been trying to add librdkafka as an external library and use it inside my cpp code but when I try to compile it and generate the wasm file, I get this error:

wasm-ld: error: unknown file type: /usr/lib/x86_64-linux-gnu/librdkafka++.a(ConfImpl.o)
em++: error: '/emsdk/upstream/bin/wasm-ld -o OUTPUT.wasm /tmp/emscripten_temp_1xep1tez/myproject_0.o /tmp/emscripten_temp_1xep1tez/proxy_wasm_intrinsics_lite.pb_1.o /tmp/emscripten_temp_1xep1tez/struct_lite.pb_2.o /tmp/emscripten_temp_1xep1tez/proxy_wasm_intrinsics_3.o /sdk/libprotobuf-lite.a /usr/lib/x86_64-linux-gnu/librdkafka++.a -L/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto /emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/crt1_reactor.o -lGL -lal -lhtml5 -lstandalonewasm -lstubs -lnoexit -lc -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --strip-debug --export-if-defined=malloc --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=malloc --export-table -z stack-size=5242880 --initial-memory=16777216 --entry=_initialize --max-memory=16777216 --global-base=1024' failed (returned 1)
make: *** [OUTPUT.wasm] Error 1
Makefile:15: recipe for target 'OUTPUT.wasm' failed

I've searched about the error and according to this link, it seems that adding some link files to em++ options is not possible.
How can I do so? Is there a better way for reading a request and sending a Kafka message in envoy?
I've also attached the files that I made some changes to them here:
sample.zip

Activity

  1. changed the title [-]Using external library (in my case, librdkafka)[/-] [+]Using an external library (in my case, librdkafka)[/+] on Jul 11, 2022
  2. PiotrSikora commented on Jul 11, 2022

    @PiotrSikora
    Member

    You're trying to link together Proxy-Wasm plugin (built for wasm32 architecture) and system library (built for x86_64 architecture). This won't work, you need to build librdkafka++ from sources for wasm32 target as part of the plugin itself.

  3. amirEBD commented on Jul 12, 2022

    @amirEBD

    I had the same issue with proxy-wasm as @MMahdiSetak mentioned, how can I get a wasm32 build for librdkafa++. @PiotrSikora
    Thansk for any help :)

  4. PiotrSikora commented on Jul 12, 2022

    @PiotrSikora
    Member

    You need to build it from sources as part of the plugin build process (assuming it even compiles to wasm32, since that's not guaranteed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions