cppkafka
cppkafka copied to clipboard
Linker errors on clang 7.0.1 on Linux
I built cppkafka (v0.3.0 release) with:
CPPKAFKA_BUILD_SHARED OFF
CPPKAFKA_RDKAFKA_STATIC_LIB ON
cppkafka build was successful.
Tried building consumer_dispatcher_example.cpp. Works on g++ 8.1.0 but when built (both the example and cppkafka) with clang++7.0.1 it cannot find a few symbols from librdkafka.a:
.../cppkafka/lib/libcppkafka.a(error.cpp.o): In function `cppkafka::Error::to_string[abi:cxx11]() const':
.../cppkafka/src/error.cpp:48: undefined reference to `rd_kafka_err2str'
.../cppkafka/lib/libcppkafka.a(metadata.cpp.o): In function `Metadata':
.../cppkafka/src/metadata.cpp:128: undefined reference to `rd_kafka_metadata_destroy'
Any idea why that might be happening?
How are you building the example? By running make examples?
I was building it directly passing files into compiler (without a Makefile). Did couple more checks - it seems to be not working with either g++ or clang++ as long as optimisation mode is less than O2. Works perfectly fine with O2 and O3, cannot find the symbols if built with O0 or O1. Very strange.
Are you linking with rdkafka? Because that would do it.
use 'ldd your_binary' command, see the output.