Code Monkey home page Code Monkey logo

Comments (17)

gbxu avatar gbxu commented on August 16, 2024 1

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

from cppkafka.

mfontanini avatar mfontanini commented on August 16, 2024

Did you run sudo ldconfig after installing both libraries?

from cppkafka.

ahoora08 avatar ahoora08 commented on August 16, 2024

No, I did the following steps:

  1. mkdir build

  2. cd build

  3. cmake ..

  4. make

  5. sudo make install

from cppkafka.

mfontanini avatar mfontanini commented on August 16, 2024

from cppkafka.

ahoora08 avatar ahoora08 commented on August 16, 2024

Thanks, I ran it. But still there is no .cpp file in directory /usr/local/include/cppkafka. It should be?

from cppkafka.

mfontanini avatar mfontanini commented on August 16, 2024

from cppkafka.

ahoora08 avatar ahoora08 commented on August 16, 2024

No, I didn't link my project to cppkafka and lrdkafka. Can you clarify that pls? Thanks

from cppkafka.

mfontanini avatar mfontanini commented on August 16, 2024

from cppkafka.

ahoora08 avatar ahoora08 commented on August 16, 2024

Thanks for your answering. You know I'm C++ coder but totally newbie to making libraries.
I created a project using clion and run code there. Can you say more details how and where I should link them? In which step?

Thanks in advanced

from cppkafka.

ahoora08 avatar ahoora08 commented on August 16, 2024

Which one should I link to? cppkafka and rdkafka I downloaded from github or cppkafka and rdkafka created in path /usr/local/include after doing make?

from cppkafka.

mfontanini avatar mfontanini commented on August 16, 2024

I have never used CLion. Search for how to configure the compiler link flags and add "-lcppkafka -lrdkafka" to them.

from cppkafka.

ahoora08 avatar ahoora08 commented on August 16, 2024

Thanks, now it errors undefined reference to boost::program_options::options_description::m_default_line_length'|

it's because of boost
How can I fix that?

from cppkafka.

mfontanini avatar mfontanini commented on August 16, 2024

from cppkafka.

ahoora08 avatar ahoora08 commented on August 16, 2024

That's it, using -lboost_program_options, It works
Thanks a lot!!!!!!!!!!!

from cppkafka.

gbxu avatar gbxu commented on August 16, 2024

I solve it. I should learn how to use cmake!
I modify the CMakeLists.txt

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")
FIND_LIBRARY(RDKAFKA rdkafka /usr/local/lib NO_DEFAULT_PATH)
FIND_LIBRARY(CPPKAFKA cppkafka /usr/local/lib NO_DEFAULT_PATH)
link_libraries(${RDKAFKA} ${CPPKAFKA})
add_executable(test src/main.cpp)
target_link_libraries(test cppkafka)
target_link_libraries(test rdkafka)

now It works well!

from cppkafka.

mfontanini avatar mfontanini commented on August 16, 2024

I think you just had to run ldconfig as root right after installing cppkafka.

from cppkafka.

gbxu avatar gbxu commented on August 16, 2024

@mfontanini I runned sudo ldconfig before. and the CMakeLists.txt is as follows:

cmake_minimum_required(VERSION 3.10)
project(test)
set(CMAKE_CXX_STANDARD 11)
add_executable(test src/main.cpp)

The problem happens.
I try the steps again and get the same result. It bothers me.


should I modify /etc/ld.so.conf ?
But when I run ldconfig -p|grep kafka , it shows

	librdkafka.so.1 (libc6,x86-64) => /usr/local/lib/librdkafka.so.1
	librdkafka.so (libc6,x86-64) => /usr/local/lib/librdkafka.so
	librdkafka++.so.1 (libc6,x86-64) => /usr/local/lib/librdkafka++.so.1
	librdkafka++.so (libc6,x86-64) => /usr/local/lib/librdkafka++.so
	libcppkafka.so.0.1 (libc6,x86-64) => /usr/local/lib/libcppkafka.so.0.1
	libcppkafka.so (libc6,x86-64) => /usr/local/lib/libcppkafka.so

from cppkafka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.