Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when compiling against librdkafka with g++ (as opposed to gcc), even with extern "C" #36

Closed
winbatch opened this issue Dec 27, 2013 · 6 comments

Comments

@winbatch
Copy link

Hi,

I had to make a change to get a C++ program to compile against librdkafka even with extern "C" of the header file. I think the error is less about C vs. C++ though but perhaps related to more strict error checking.

rd_kafka_message_errstr returns a const char *, however, it is returning the rkmessage->payload, which is a void *. I had to add cast it to const char * in the return statement to get it to compile.

@zokusai
Copy link

zokusai commented Dec 27, 2013

Hi,

I had to do the same using the diff patch:

diff --git a/rdkafka.h b/rdkafka.h
index 15e7abd..327fa71 100644
--- a/rdkafka.h
+++ b/rdkafka.h
@@ -477,7 +477,7 @@ rd_kafka_message_errstr (const rd_kafka_message_t *rkmessage) {
                return NULL;

        if (rkmessage->payload)
-               return rkmessage->payload;
+               return (const char *) rkmessage->payload;

        return rd_kafka_err2str(rkmessage->err);
 }

Also (maybe a Cygwin issue), I had to modify the Makefiles to discard the -Werror flag in order to compile:

diff --git a/examples/Makefile b/examples/Makefile
index 4f96afa..a142ec9 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -1,7 +1,7 @@
 EXAMPLES ?= rdkafka_example rdkafka_performance
 CC ?= cc
 CXX ?= g++
-CFLAGS += -g -Wall -Werror -Wfloat-equal -Wpointer-arith -O2 -I../
+CFLAGS += -g -Wall -Wfloat-equal -Wpointer-arith -O2 -I../
 CXXFLAGS += $(CFLAGS)
 LDFLAGS +=  ../librdkafka.a
 LDFLAGS += -lpthread -lz
diff --git a/Makefile b/Makefile
index 8fce227..dd06293 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ HDRS= rdkafka.h
 OBJS=  $(SRCS:.c=.o)
 DEPS=  ${OBJS:%.o=%.d}

-CFLAGS+=-O2 -Wall -Werror -Wfloat-equal -Wpointer-arith -fPIC -I.
+CFLAGS+=-O2 -Wall -Wfloat-equal -Wpointer-arith -fPIC -I.
 CFLAGS+=-g

 # Clang warnings to ignore

You may ask why Cygwin? Well, limitations of developer workstation on a restricted environment, not intended for the final deployment.

@edenhill
Copy link
Contributor

Thank you both for reporting this.

@winbatch
Copy link
Author

I think you might also want to do extern "C" around rdkafka.h. This way users who include it don't have to do it themselves when doing the include?

@edenhill
Copy link
Contributor

I will release a proper C++ interface end of january.

@winbatch
Copy link
Author

Looking forward to it. Will that be in partnership with https://github.com/adobe-research/libkafka or in competition? (I actually started using libkafka in the beginning and switched to librdkafka based on its better handling of my requirements)

@edenhill
Copy link
Contributor

This will be a proper C++ interface on top of the librdkafka's C interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants