如何将C++应用程序与 cppkafka 链接

How to link C++ Application with cppkafka

本文关键字:cppkafka 链接 应用程序 C++      更新时间:2023-10-16

正如cppkafka官方GitHub在使用部分提到的。

如果你想使用 cppkafka,你需要将你的应用程序链接到:

  • CPPKAFKA
  • 德卡夫卡

我尝试编译 GitHub README.md 中提到的示例程序

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

它抛出并出现以下错误

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
编译

时不需要 -D_GLIBCXX_USE_CXX11_ABI=0 选项。您可以简单地将其编译如下

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