cpp-redis / cpp_redis

C++11 Lightweight Redis client: async, thread-safe, no dependency, pipelining, multi-platform
MIT License
713 stars 198 forks source link

error while compile #66

Closed zhuangh7 closed 4 years ago

zhuangh7 commented 4 years ago

Describe the bug I try to test code in the example markdown as :

#include <cpp_redis/cpp_redis>

#include <iostream>

#ifdef _WIN32
#include <Winsock2.h>
#endif /* _WIN32 */

int
main(void) {
#ifdef _WIN32
  //! Windows netword DLL init
  WORD version = MAKEWORD(2, 2);
  WSADATA data;

  if (WSAStartup(version, &data) != 0) {
    std::cerr << "WSAStartup() failure" << std::endl;
    return -1;
  }
#endif /* _WIN32 */

  //! Enable logging
  cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);

  cpp_redis::client client;

  client.connect("127.0.0.1", 6379, [](const std::string& host, std::size_t port, cpp_redis::client::connect_state status) {
    if (status == cpp_redis::client::connect_state::dropped) {
      std::cout << "client disconnected from " << host << ":" << port << std::endl;
    }
  });

  // same as client.send({ "SET", "hello", "42" }, ...)
  client.set("hello", "42", [](cpp_redis::reply& reply) {
    std::cout << "set hello 42: " << reply << std::endl;
    // if (reply.is_string())
    //   do_something_with_string(reply.as_string())
  });

  // same as client.send({ "DECRBY", "hello", 12 }, ...)
  client.decrby("hello", 12, [](cpp_redis::reply& reply) {
    std::cout << "decrby hello 12: " << reply << std::endl;
    // if (reply.is_integer())
    //   do_something_with_integer(reply.as_integer())
  });

  // same as client.send({ "GET", "hello" }, ...)
  client.get("hello", [](cpp_redis::reply& reply) {
    std::cout << "get hello: " << reply << std::endl;
    // if (reply.is_string())
    //   do_something_with_string(reply.as_string())
  });

  // commands are pipelined and only sent when client.commit() is called
  // client.commit();

  // synchronous commit, no timeout
  client.sync_commit();

// synchronous commit, timeout
// client.sync_commit(std::chrono::milliseconds(100));

#ifdef _WIN32
  WSACleanup();
#endif /* _WIN32 */

  return 0;
}

I follow the command line in https://github.com/cpp-redis/cpp_redis/wiki/Mac-&-Linux-Install to install cpp_redis

and use

gcc -lstdc++ -lcpp_redis -ltacopie --std=c++11 test_redis.cpp -o testredis

to compile the code.

But it come out a error :

bash-5.0# gcc -lstdc++ -lcpp_redis -ltacopie --std=c++11 test_redis.cpp -o testredis
test_redis.cpp: In function 'int main()':
test_redis.cpp:27:104: error: 'cpp_redis::client::connect_state' has not been declared
   27 |     client.connect("127.0.0.1", 6379, [](const std::string& host, std::size_t port, cpp_redis::client::connect_state status) {
      |                                                                                                        ^~~~~~~~~~~~~
test_redis.cpp: In lambda function:
test_redis.cpp:28:46: error: 'cpp_redis::client::connect_state' has not been declared
   28 |             if (status == cpp_redis::client::connect_state::dropped) {
      |                                              ^~~~~~~~~~~~~
test_redis.cpp: In function 'int main()':
test_redis.cpp:31:14: error: no matching function for call to 'cpp_redis::client::connect(const char [10], int, main()::<lambda(const string&, std::size_t, int)>)'
   31 |             });
      |              ^
In file included from /usr/local/include/cpp_redis/cpp_redis:30,
                 from test_redis.cpp:1:
/usr/local/include/cpp_redis/core/client.hpp:116:9: note: candidate: 'void cpp_redis::client::connect(const string&, std::size_t, const connect_callback_t&, uint32_t, int32_t, uint32_t)'
  116 |    void connect(
      |         ^~~~~~~
/usr/local/include/cpp_redis/core/client.hpp:119:32: note:   no known conversion for argument 3 from 'main()::<lambda(const string&, std::size_t, int)>' to 'const connect_callback_t&' {aka 'const std::function<void(const std::__cxx11::basic_string<char>&, long unsigned int, cpp_redis::connect_state)>&'}
  119 |      const connect_callback_t &connect_callback = nullptr,
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/cpp_redis/core/client.hpp:134:9: note: candidate: 'void cpp_redis::client::connect(const string&, const connect_callback_t&, uint32_t, int32_t, uint32_t)'
  134 |    void connect(
      |         ^~~~~~~
/usr/local/include/cpp_redis/core/client.hpp:136:32: note:   no known conversion for argument 2 from 'int' to 'const connect_callback_t&' {aka 'const std::function<void(const std::__cxx11::basic_string<char>&, long unsigned int, cpp_redis::connect_state)>&'}
  136 |      const connect_callback_t &connect_callback = nullptr,
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~

To Reproduce Steps to reproduce the behavior:

  1. follow https://github.com/cpp-redis/cpp_redis/wiki/Mac-&-Linux-Install to install cpp_redis
  2. copy code in https://github.com/cpp-redis/cpp_redis/wiki/Examples#redis-client to a file(test_redis.cpp)
  3. try gcc -lstdc++ -lcpp_redis -ltacopie --std=c++11 test_redis.cpp -o testredis to compile

Expected behavior compile success with no error or warning.

Screenshots all codes, steps and outputs have been shown above.

Desktop (please complete the following information):

zhuangh7 commented 4 years ago

I find that the connect_state is actually define under cpp_redis namespace, and I change the code to

client.connect("127.0.0.1", 6379, [](const std::string& host, std::size_t port, cpp_redis::connect_state status) {                           
  if (status == cpp_redis::connect_state::dropped) {                                                                                   
std::cout << "client disconnected from " << host << ":" << port << std::endl;                                                        
  }                                                                                                                                    
});    

and try to use gcc -lstdc++ -lcpp_redis -ltacopie --std=c++11 test_redis.cpp -o testredis again. And I got:

bash-5.0# gcc -lstdc++ -lcpp_redis -ltacopie --std=c++11 test_redis.cpp -o testredis
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccDjGfje.o: in function `main::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, cpp_redis::connect_state)#1}::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, cpp_redis::connect_state) const':
test_redis.cpp:(.text+0x27): undefined reference to `std::cout'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x2c): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x3e): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x4d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x5f): undefined reference to `std::ostream::operator<<(unsigned long)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x69): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x74): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccDjGfje.o: in function `main::{lambda(cpp_redis::reply
&)#2}::operator()(cpp_redis::reply&) const':
test_redis.cpp:(.text+0x96): undefined reference to `std::cout'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x9b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0xad): undefined reference to `operator<<(std::ostream&, cpp_redis::reply const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0xb7): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0xc2): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccDjGfje.o: in function `main::{lambda(cpp_redis::reply&)#3}::operator()(cpp_redis::reply&) const':
test_redis.cpp:(.text+0xe4): undefined reference to `std::cout'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0xe9): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*
)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0xfb): undefined reference to `operator<<(std::ostream&, cpp_redis::reply const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x105): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x110): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccDjGfje.o: in function `main::{lambda(cpp_redis::reply&)#4}::operator()(cpp_redis::reply&) const':
test_redis.cpp:(.text+0x132): undefined reference to `std::cout'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x137): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x149): undefined reference to `operator<<(std::ostream&, cpp_redis::reply const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x153): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x15e): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccDjGfje.o: in function `main':
test_redis.cpp:(.text+0x186): undefined reference to `operator new(unsigned long)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x19a): undefined reference to `cpp_redis::logger::logger(cpp_redis::logger::log_level)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x1c1): undefined reference to `cpp_redis::active_logger'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x1e4): undefined reference to `cpp_redis::client::client()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x202): undefined reference to `std::allocator<char>::allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x21f): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x256): 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)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x269): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x278): undefined reference to `std::allocator<char>::~allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x2a5): undefined reference to `std::allocator<char>::allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x2c2): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x2d1): undefined reference to `std::allocator<char>::allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x2ee): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x312): 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&, std::function<void (cpp_redis::reply&)> const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x321): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x330): undefined reference to `std::allocator<char>::~allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x33f): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x34e): undefined reference to `std::allocator<char>::~allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x37b): undefined reference to `std::allocator<char>::allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x398): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x3bd): undefined reference to `cpp_redis::client::decrby(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, std::function<void (cpp_redis::reply&)> const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x3cc): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x3db): undefined reference to `std::allocator<char>::~allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x408): undefined reference to `std::allocator<char>::allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x425): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x445): 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&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x454): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x463): undefined reference to `std::allocator<char>::~allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x481): undefined reference to `cpp_redis::client::sync_commit()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x495): undefined reference to `cpp_redis::client::~client()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x4be): undefined reference to `operator delete(void*)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x4db): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x4ef): undefined reference to `std::allocator<char>::~allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x515): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x529): undefined reference to `std::allocator<char>::~allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x538): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x54c): undefined reference to `std::allocator<char>::~allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x56f): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x583): undefined reference to `std::allocator<char>::~allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x5a6): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x5ba): undefined reference to `std::allocator<char>::~allocator()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x5dd): undefined reference to `cpp_redis::client::~client()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccDjGfje.o: in function `__static_initialization_and_destruction_0(int, int)':
test_redis.cpp:(.text+0x1265): undefined reference to `std::ios_base::Init::Init()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x127a): undefined reference to `std::ios_base::Init::~Init()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccDjGfje.o:(.data.rel.ro+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccDjGfje.o:(.data.rel.ro+0x10): undefined reference to `vtable for __cxxabiv1::__class_type_info'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccDjGfje.o:(.data.rel.ro+0x20): undefined reference to `vtable for __cxxabiv1::__class_type_info'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccDjGfje.o:(.data.rel.ro+0x30): undefined reference to `vtable for __cxxabiv1::__class_type_info'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccDjGfje.o:(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
zhuangh7 commented 4 years ago

I change to use g++ and the response is :

bash-5.0# g++ -lcpp_redis -ltacopie --std=c++11 test_redis.cpp -o testredis
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cccBpghH.o: in function `main::{lambda(cpp_redis::reply&)#2}::operator()(cpp_redis::reply&) const':
test_redis.cpp:(.text+0xad): undefined reference to `operator<<(std::ostream&, cpp_redis::reply const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cccBpghH.o: in function `main::{lambda(cpp_redis::reply&)#3}::operator()(cpp_redis::reply&) const':
test_redis.cpp:(.text+0xfb): undefined reference to `operator<<(std::ostream&, cpp_redis::reply const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cccBpghH.o: in function `main::{lambda(cpp_redis::reply&)#4}::operator()(cpp_redis::reply&) const':
test_redis.cpp:(.text+0x149): undefined reference to `operator<<(std::ostream&, cpp_redis::reply const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cccBpghH.o: in function `main':
test_redis.cpp:(.text+0x19a): undefined reference to `cpp_redis::logger::logger(cpp_redis::logger::log_level)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x1c1): undefined reference to `cpp_redis::active_logger'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x1e4): undefined reference to `cpp_redis::client::client()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x256): 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)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x312): 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&, std::function<void (cpp_redis::reply&)> const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x3bd): undefined reference to `cpp_redis::client::decrby(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, std::function<void (cpp_redis::reply&)> const&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x445): 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&)'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x481): undefined reference to `cpp_redis::client::sync_commit()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x495): undefined reference to `cpp_redis::client::~client()'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: test_redis.cpp:(.text+0x5dd): undefined reference to `cpp_redis::client::~client()'
collect2: error: ld returned 1 exit status