我需要摆脱 cmake ,所以我想在 mingw 上构建一个 qmake 项目。请帮助我了解缺少的内容。从https://github.com/mfontanini/cppkafka构建CPPKafka
main.cpp
#include <cppkafka/cppkafka.h>
using namespace std;
using namespace cppkafka;
int main() {
Configuration config = { // Create the config
{ "metadata.broker.list", "127.0.0.1:9092" }
};
Producer producer(config); // Create the producer
string message = "hey there!"; // Produce a message!
producer.produce(MessageBuilder("my_topic").partition(0).payload(message));
producer.flush();
return 0;
}
.pro文件TEMPLATE = app
CONFIG += console c++14
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
INCLUDEPATH += 'C:\Program Files\CppKafka\include' \
'C:\Program Files\RdKafka\include' \
'C:\boost_1_72_0' \
'C:\Program Files\CppKafka\include\cppkafka'
LIBS += 'C:\Program Files\RdKafka\bin\librdkafka.dll' \
'C:\Program Files\RdKafka\bin\librdkafka++.dll' \
-lpthread \
-lz \
-lstdc++ \
'C:\Program Files\CppKafka\bin\libcppkafka.dll'
命令链接错误
cmake
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
include_directories('C:\Program Files\RdKafka\include')
include_directories(C:\boost_1_72_0)
add_custom_target(examples)
macro(create_example example_name)
string(REPLACE "_" "-" sanitized_name ${example_name})
add_executable(${sanitized_name} EXCLUDE_FROM_ALL "${example_name}_example.cpp")
target_link_libraries(${sanitized_name} cppkafka RdKafka::rdkafka Boost::boost Boost::program_options)
add_dependencies(examples ${sanitized_name})
endmacro()
create_example(producer)
create_example(buffered_producer)
create_example(consumer)
create_example(consumer_dispatcher)
create_example(metadata)
create_example(consumers_information)
最佳答案
您需要将dllexport
添加到struct HandleDeleter
并进行重建。
在include\cppkafka\kafka_handle_base.h
之前:
struct HandleDeleter {
explicit HandleDeleter(const KafkaHandleBase* handle_base_ptr) : handle_base_ptr_{handle_base_ptr} {}
void operator()(rd_kafka_t* handle);
private:
const KafkaHandleBase * handle_base_ptr_;
};
后:struct CPPKAFKA_API HandleDeleter {
explicit HandleDeleter(const KafkaHandleBase* handle_base_ptr) : handle_base_ptr_{handle_base_ptr} {}
void operator()(rd_kafka_t* handle);
private:
const KafkaHandleBase * handle_base_ptr_;
};