Comments (17)
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.
Did you run sudo ldconfig
after installing both libraries?
from cppkafka.
No, I did the following steps:
-
mkdir build
-
cd build
-
cmake ..
-
make
-
sudo make install
from cppkafka.
from cppkafka.
Thanks, I ran it. But still there is no .cpp
file in directory /usr/local/include/cppkafka
. It should be?
from cppkafka.
from cppkafka.
No, I didn't link my project to cppkafka
and lrdkafka
. Can you clarify that pls? Thanks
from cppkafka.
from cppkafka.
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.
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.
I have never used CLion. Search for how to configure the compiler link flags and add "-lcppkafka -lrdkafka" to them.
from cppkafka.
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.
from cppkafka.
That's it, using -lboost_program_options, It works
Thanks a lot!!!!!!!!!!!
from cppkafka.
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.
I think you just had to run ldconfig
as root right after installing cppkafka.
from cppkafka.
@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)
- Cannot pull using consumer HOT 1
- poll_batch does not trigger commit when auto.commit is true ? HOT 1
- How to remove topic using the API
- Consumer misbehavior with newer librdkafka versions HOT 1
- Can't build tests on Ubuntu 22.04 (Jammy)
- produer success but kafka shell consumer all "null" HOT 1
- How to use BufferedProducer to send binary data?
- Dll import function not allowed
- create BufferedProducer<std::string> producer globally
- Is there any way to build it without "boost"? HOT 1
- Please help me, I have tried a variety of methods to compile, all failed, including using the method provided by chatGPT 4.0. also failed. HOT 1
- How to set ttl?
- How to get number of messages in the topic?
- add_library(Rdkafka::rdkafka) issue
- CPPKafka crashes when trying to create a configuration in Windows
- What happens if Kafka was offline ? HOT 1
- Automate Compilation of "examples" in Build Process
- warning: object backing the pointer will be destroyed at the end of the full-expression
- cppkafka::produce not flushing
- clang complains about parameter used in std::atomic_flag constructor
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cppkafka.