sewenew/redis-plus-plus

Redis++ connection returns NULL on Windows

andrewjohnstonn opened this issue · 6 comments

I have been trying to build a Redis++ application on Windows but I am still unable to establish a connection with my Redis-server. I'm wondering if anyone has successfully built a CMake application on Windows as I have a feeling it is something in my CMake that is wrong as the provided test passes everything. I have included my CMake below.

cmake_minimum_required(VERSION 3.16.4)
 
project(RedisProject)
 
set(REDIS_PLUS_PLUS_CXX_STANDARD=17)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(HIREDIS_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/../")
set(HIREDIS_LIB "${CMAKE_CURRENT_SOURCE_DIR}/../hiredis/build/Debug/hiredisd.lib")
set(REDIS_PLUS_PLUS_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/../redis-plus-plus/src")
set(REDIS_PLUS_PLUS_LIB "${CMAKE_CURRENT_SOURCE_DIR}/../redis-plus-plus/build/Debug/redis++_static.lib")
 

file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*h ${CMAKE_CURRENT_SOURCE_DIR}/*cpp)
 
add_executable(redis ${sources})
 
target_include_directories(redis PUBLIC "${CMAKE_SOURCE_DIR}/../redis-plus-plus/src/sw/redis++/cxx17")
target_include_directories(redis PUBLIC "${CMAKE_SOURCE_DIR}/../redis-plus-plus/src/sw/redis++/tls")
 
find_path(HIREDIS_HEADER hiredis)
target_include_directories(redis PUBLIC ${HIREDIS_HEADER})
 
find_library(HIREDIS_LIB hiredis)
target_link_libraries(redis ${HIREDIS_LIB})
 
find_path(REDIS_PLUS_PLUS_HEADER sw)
target_include_directories(redis PUBLIC ${REDIS_PLUS_PLUS_HEADER})
 
find_library(REDIS_PLUS_PLUS_LIB redis++_static)
target_link_libraries(redis ${REDIS_PLUS_PLUS_LIB})

Environment:

  • OS: Windows
  • Compiler: MSVC
  • hiredis version: master
  • redis-plus-plus version: master

I'll also note my cpp program is literally just:

auto client = sw::redis::Redis("tcp://host:6379")

std::cout << client.ping();

It seems that you didn't finish the install steps, but built with redis-plus-plus' source code? That should not work.

Instead, you should build redis-plus-plus with cmake, and run make install to install headers and libs. The installation process will do some critical stuff to ensure related headers are installed correctly.

NOTE: redis-plus-plus does not return NULL pointer, it throws exception when error happens.

Regards

No make file is generated on Windows when I cmake .. in the build folder

I also get an error when I run make in the hiredis folder on Windows:

$ make
Makefile:102: Extraneous text after `else' directive
gcc -std=c99 -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb -pedantic alloc.c
alloc.c:1:0: warning: -fPIC ignored for target (all code is position independent) [enabled by default]
alloc.c:40:17: error: 'strdup' undeclared here (not in a function)
make: *** [alloc.o] Error 1

Hi,

Got it working, you were right I just had to build using Visual Studio I was building manually on VS Code.

Cheers!