I'm working on a Windows C++ project utilizing CMake for building. The primary challenge is establishing a connection to my local Kafka docker container. Upon running the executable, it exits due to a failure in setting 'bootstrap.servers'. Even when I attempted to build and execute the sample 'producer.cpp' code from the librdkafka GitHub repository, I encountered the same setback. Strangely, when I replicated the code in my WSL2 Ubuntu environment, it worked seamlessly.
I incorporated VCpkg as a toolchain in CMake and downloaded Librdkafka, which resulted in successful execution. Hence, it seems the issue doesn't lie within the C++ code itself since it operates in WSL2 and with VCpkg. However, there seems to be an additional step required in CMake specifically for Windows, yet I'm uncertain about its nature.
Could someone guide me on the potential additional steps or configurations necessary in CMake for successful connection to Kafka when building on Windows? OS: Windows 11 CMake: 3.24.1 CMake Generator: Visual Studio 17 2022 CXX compiler: MSVC 19.38.33130.0
My CMakeLists.txt file is
cmake_minimum_required(VERSION 3.20)
project(Kafka CXX)
include(FetchContent)
find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)
option(RDKAFKA_BUILD_STATIC ON)
option(RDKAFKA_BUILD_EXAMPLES OFF)
option(RDKAFKA_BUILD_TESTS OFF)
FetchContent_Declare(
rdkafka
GIT_REPOSITORY https://github.com/confluentinc/librdkafka
GIT_TAG v2.2.0
)
FetchContent_MakeAvailable(rdkafka)
add_executable(${PROJECT_NAME} main.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC ${rdkafka_SOURCE_DIR}/src-cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC rdkafka++)