sewenew / redis-plus-plus

Redis client written in C++
Apache License 2.0
1.64k stars 351 forks source link

Undefined Symbol on redis.subscriber() #533

Closed thomasmurphycodes closed 10 months ago

thomasmurphycodes commented 11 months ago

The issue is that I am able to run redis.get() and redis.set(), but compilation fails if I try to create a subscriber() object. I am following the CMake example provided in the README. Are there additional symbols to be linked to make subscriber() able to be compiled?

Minimal reproduceable example:

#define CPPHTTPLIB_OPENSSL_SUPPORT
#include <sw/redis++/redis++.h>

using namespace sw::redis;
// Create an Redis object, which is movable but NOT copyable.
Redis redis = Redis("tcp://127.0.0.1:6379");

int main() {
    auto sub = redis.subscriber();
    return 0;
}

Compilation error:

Undefined symbols for architecture arm64:
  "_redisFree", referenced from:
      sw::redis::Connection::ContextDeleter::operator()(redisContext*) const in main.cpp.o

Platform: Mac OSX 12.3.1 Compilation command: /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/thomasmurphy/CLionProjects/remote_build_test/cmake-build-debug --target remote_build_test -- -j 6

sewenew commented 11 months ago

Sorry but I cannot reproduce your problem.

However, I'm not sure if the macro CPPHTTPLIB_OPENSSL_SUPPORT you defined, e.g. other libs included, has any impact on it. Could you please remove other dependencies, and retry it?

Regards

sewenew commented 11 months ago

Also, please ensure that you linked with libhiredis.a or libhiredis.so. _redisFree is defined by hiredis, and your error message shows that the related symbols is not defined. Normally, you can fix this problem by linking libhiredis.

Regards

thomasmurphycodes commented 11 months ago

I will try to get a repro going in isolation reflecting comments above in next couple of days - thanks!

sewenew commented 10 months ago

Since there's no update, I'll close this issue.

Regards