undefined reference to `operator<<(std::ostream&, cpp_redis::reply const&)'
cccnrc opened this issue · 2 comments
cccnrc commented
I followed the installation procedure (https://github.com/Cylix/cpp_redis/wiki/Mac-&-Linux-Install), using the updated library instead of the old one:
# ... rest of procedure described in link
git clone https://github.com/cpp-redis/cpp_redis.git
# ... rest of procedure described in link
Now when I try to run a program (even
cpp_redis_client.cpp
in the example dir) I got the error:
/tmp/ccptfGnr.o: In function `main::{lambda(cpp_redis::reply&)#1}::operator()(cpp_redis::reply&) const':
ex0.cpp:(.text+0xc5): undefined reference to `operator<<(std::ostream&, cpp_redis::reply const&)'
/tmp/ccptfGnr.o: In function `main':
ex0.cpp:(.text+0x105): undefined reference to `cpp_redis::client::client()'
ex0.cpp:(.text+0x17c): undefined reference to `cpp_redis::client::connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, std::function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, cpp_redis::connect_state)> const&, unsigned int, int, unsigned int)'
ex0.cpp:(.text+0x223): undefined reference to `cpp_redis::client::set(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
ex0.cpp:(.text+0x2bd): undefined reference to `cpp_redis::client::get(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void (cpp_redis::reply&)> const&)'
ex0.cpp:(.text+0x2f0): undefined reference to `cpp_redis::client::sync_commit()'
ex0.cpp:(.text+0x304): undefined reference to `cpp_redis::client::~client()'
ex0.cpp:(.text+0x3ca): undefined reference to `cpp_redis::client::~client()'
collect2: error: ld returned 1 exit status
I tried with#include <iostream>
but nothing worked.
Here my code:
#include <string>
#include <cpp_redis/cpp_redis>
#include <cpp_redis/misc/macro.hpp>
#include <iostream>
/*
to compile:
gcc -lstdc++ --std=c++11 \
ex0.cpp \
-o ex0 \
&& time ./ex0
*/
int main(int argc, char const *argv[]) {
// cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);
cpp_redis::client client;
client.connect();
client.set("hello", "42");
client.get("hello", [](cpp_redis::reply& reply) {
std::cout << reply << std::endl;
});
//! also support std::future
//! std::future<cpp_redis::reply> get_reply = client.get("hello");
client.sync_commit();
//! or client.commit(); for asynchronous call
return 0;
}
Compiled through gcc:
gcc -lstdc++ --std=c++11 ex0.cpp -o ex0
Thanks a lot in advance for any help!
dobeeisfree commented
dhruvkakadiya commented
gcc -lstdc++ -lcpp_redis -ltacopie --std=c++11 ex0.cpp -o ex0