cppkafka: `undefined reference to *` error on building consumer example

Hi, First I installed librdkafka using instruction successfully. After that I installed cppkafka using document instruction, in addition command sudo make install at the end. So now both librdkafka and cppkafka are in directories /usr/local/lib and /usr/local/include. Trying to build consumer example code, the IDE(both Clion and Eclipse) resolved including libraries and show hints in using methods, but in building I faced error undefined reference to methods and classes. I check directory /usr/local/include and it only contains the .h files!

Did I do any steps wrong?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

i have the same problem. i install rdkafka and cppkafka, then i write main.cpp

#include <cppkafka/producer.h>
using namespace std;
using namespace cppkafka;
int main() {
    // Create the config
    Configuration config = {
        { "metadata.broker.list", "127.0.0.1:9092" }
    };

    // Create the producer
    Producer producer(config);

    // Produce a message!
    string message = "hey there!";
    producer.produce(MessageBuilder("my_topic").partition(0).payload(message));
    producer.flush();
}

i write the CMakeLists.txt as follows:

cmake_minimum_required(VERSION 3.10)
project(test)
set(CMAKE_CXX_STANDARD 11)
include_directories("/usr/local/include/librdkafka")
include_directories("/usr/local/include/cppkafka")
link_libraries("/usr/local/lib")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lrdkafka++ -lrdkafka -lcppkafka")
add_executable(test main.cpp)

but when i compile and run the main.cpp it shows:

undefined reference to `cppkafka::ConfigurationOption::ConfigurationOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*)'
undefined reference to `cppkafka::Configuration::Configuration(std::initializer_list<cppkafka::ConfigurationOption> const&)'
...

what did i miss? gcc 5.4 ubuntu 16.04