undefined reference to `rd_kafka_err2str’ when using librdkafka

  apache-kafka, c++, librdkafka

I’m trying to build a project that uses modern-cpp-kafka but get an undefined reference to rd_kafka_err2str. I used vcpkg to install librdkafka and have the directories included in my CMakeLists file. All other librdkafka references work, I’m only experiencing this issue with rd_kafka_err2str.

Adding -lrdkafka to my CMAKE_CXX_FLAGS didn’t seem to help.

Here is the output of my build:

[main] Building folder: KafkaTest 
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/jordan/source/KafkaTest/build --config Debug --target all -- -j 10
[build] Scanning dependencies of target KafkaTest
[build] [ 50%] Building CXX object CMakeFiles/KafkaTest.dir/KafkaTest.cpp.o
[build] [100%] Linking CXX executable KafkaTest
[build] /usr/bin/ld: CMakeFiles/KafkaTest.dir/KafkaTest.cpp.o: in function `kafka::ErrorCategory::message[abi:cxx11](int) const':
[build] /home/jordan/source/modern-cpp-kafka/include/kafka/Error.h:16: undefined reference to `rd_kafka_err2str'
[build] collect2: error: ld returned 1 exit status
[build] make[2]: *** [CMakeFiles/KafkaTest.dir/build.make:84: KafkaTest] Error 1
[build] make[1]: *** [CMakeFiles/Makefile2:239: CMakeFiles/KafkaTest.dir/all] Error 2
[build] make: *** [Makefile:117: all] Error 2
[build] Build finished with exit code 2

Any ideas on how I can solve this issue? I’m new to C++ so I apologize in advance for sounding stupid 🙂

Source: Windows Questions C++