tdv/redis-cpp

Undefined Reference to rediscpp::make_stream

Closed this issue · 3 comments

I compiled redis-cpp with following code
`

  1. cd /opt &&\
  2. git clone https://github.com/tdv/redis-cpp.git &&\
  3. cd redis-cpp &&\
  4. mkdir build &&\
  5. cd build &&\
  6. cmake -DREDISCPP_HEADER_ONLY=OFF -DREDISCPP_PURE_CORE=ON .. &&\
  7. make &&\
  8. make install`

On this line

auto redis_client = rediscpp::make_stream(this->redis_host, this->redis_port);

I getting below error

undefined reference to rediscpp::make_stream(std::basic_string_view<char, std::char_traits >, std::basic_string_view<char, std::char_traits >)'
collect2: error: ld returned 1 exit status`

My question is that, How to find redis-cpp in cmake and link with my code??
Any help would be appreciated.

@tdv

tdv commented

Hello.

Thank you for the request.

There is no problem related to undefined references.

I've notices that you use the flag REDISCPP_PURE_CORE=ON. That means only pure code without any buildin streams from the library. You can use that flag only in case when you'd like to extend the library by your own stream implementation or you need to use only a protocol supporting. If you want to have transport supportion out of the box, you need to use the library without flag REDISCPP_PURE_CORE or disable the one. If you saw the stream.h file, you couls notice a guard at the beginning. I have not exclude that file from the installation process when REDISCPP_PURE_CORE is enabled. I admit that's my omission and will fix it soon.

In addition, you can see how to use 'pure code', for instance, in the example 'resp' (about the protocol parsing) https://github.com/tdv/redis-cpp/tree/master/examples/resp

Regards.

@tdv Thanks for your response.
At first, compiled this library with flag REDISCPP_PURE_CORE=OFF and REDISCPP_HEADER_ONLY=ON, there was no undefined reference but I got error of multiple definitions. I wrote a class to do all redis related tasks and when include wrote class into another class, i got multiple definition errors. I also used HEADER_ONLY flag in cmake. Can you please help me with that.

Regards,

tdv commented

Unfortunately, I can't deep dive into your issue, because I'm lacked of your project's sources. Maybe, you've encountered a rare case. Nevertheless, I would propose an easy recipe for how to use the library

  • Copy all include files of the library (https://github.com/tdv/redis-cpp/tree/master/include) into your project
  • Include the library with the macro definition (#define REDISCPP_HEADER_ONLY) like in examples, for instance, described in README
  • Configure your project to use the right libraries' paths
  • Use the library like a header-only library without any need to build the one.

Hopefully, that will work and there will not be any problem to use the library.
Good luck.
Regards.