cppkafka icon indicating copy to clipboard operation
cppkafka copied to clipboard

Linker errors on clang 7.0.1 on Linux

Open luxuki opened this issue 6 years ago • 4 comments
trafficstars

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?

luxuki avatar Feb 08 '19 13:02 luxuki

How are you building the example? By running make examples?

mfontanini avatar Feb 08 '19 17:02 mfontanini

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.

luxuki avatar Feb 08 '19 22:02 luxuki

Are you linking with rdkafka? Because that would do it.

mfontanini avatar Feb 08 '19 22:02 mfontanini

use 'ldd your_binary' command, see the output.

csfreebird avatar Feb 22 '19 13:02 csfreebird