1

As mentioned in the cppkafka official GitHub in usage section.

If you want to use cppkafka, you'll need to link your application with:

  • cppkafka
  • rdkafka

I tried to compile example program mentioned in the README.md of the GitHub with

gcc -O3 -Wall test.cpp -std=c++11 -lrdkafka -lpthread -lz -lstdc++ -D_GLIBCXX_USE_CXX11_ABI=0 -lcppkafka

It is throwing with following error

test.cpp:(.text.startup+0x46): undefined reference to `cppkafka::ConfigurationOption::ConfigurationOption(std::string const&, char const*)'
test.cpp:(.text.startup+0xd9): undefined reference to `cppkafka::Buffer::Buffer(std::string const&)'
collect2: error: ld returned 1 exit status
  • `How do I compile the CPP program by linking the above the libraries` - What **exactly** is difficult for you? **Compiling** of c++ program? - Take any manual about CMake. **Linking** with the library? See [that question](https://stackoverflow.com/questions/8774593/cmake-link-to-external-library). – Tsyvarev Apr 10 '18 at 13:12
  • I linked the above libraries with -lcppkafka and -lrdkafka but the compilation is throwing with an error undefined reference to `cppkafka::ConfigurationOption::ConfigurationOption(std::string const&, char const*)' – NANDIGAM VIJAY SAI Apr 10 '18 at 16:40
  • Please, [edit] your question and describe that attempt in it. – Tsyvarev Apr 10 '18 at 17:01
  • @Tsyvarev can you look at the question now and help me to resolve the error – NANDIGAM VIJAY SAI Apr 10 '18 at 18:12
  • Oh, you just calls `gcc` for compile your program. Then, why `cmake` tag? – Tsyvarev Apr 10 '18 at 19:55
  • First I am trying with gcc. If it successfully compiled then I will move it to cmake – NANDIGAM VIJAY SAI Apr 11 '18 at 02:45
  • On Stack Overflow *tags* is what the **question post talks about**; not what do you *want* to use in the future. – Tsyvarev Apr 11 '18 at 07:20
  • As for the problem itself, it looks like compatibility problem. Make sure that you have built `cppkafka` library with the **same compiler**, as you use for your test application. – Tsyvarev Apr 11 '18 at 07:26
  • Thanks, @Tsyvarev for your time. I figured out the problem – NANDIGAM VIJAY SAI Apr 11 '18 at 12:27

1 Answers1

0

No need of -D_GLIBCXX_USE_CXX11_ABI=0 option while compiling. you can simply compile this as following

gcc -O3 -Wall test.cpp -std=c++11 -lrdkafka -lpthread -lz -lstdc++ -lcppkafka