binance-exchange / binacpp

Binance C++ library
MIT License
212 stars 108 forks source link

Undefined reference to function in binance_utils string_toupper #35

Closed rayguang closed 5 years ago

rayguang commented 5 years ago

hello,

I got some link errors. I put all binance related .h and .cpp files in the same directory as example.cpp (to resolve some errors related to to_string was not declared in this scope)

Making example

g++ -I../lib/libcurl-7.56.0/include -I../lib/jsoncpp-1.8.3/include -I../lib/libwebsockets-2.4.0/include -I../lib/libbinacpp/include \ example.cpp \ -L../lib/libcurl-7.56.0/lib \ -L../lib/libwebsockets-2.4.0/lib \ -L../lib/libbinacpp/lib \ -lcurl -lcrypto -lwebsockets -lbinacpp -o example /tmp/ccSoRo3V.o: In function BinaCPP::get_price(char const*)': example.cpp:(.text+0x64d): undefined reference tostring_toupper[abi:cxx11](char const)' /tmp/ccSoRo3V.o: In function `BinaCPP::get_bookTicker(char const, Json::Value&)': example.cpp:(.text+0xa9a): undefined reference to string_toupper[abi:cxx11](char const*)' /tmp/ccSoRo3V.o: In functionBinaCPP::get_account(long, Json::Value&)': example.cpp:(.text+0x1e93): undefined reference to hmac_sha256[abi:cxx11](char const*, char const*)' /tmp/ccSoRo3V.o: In functionBinaCPP::get_myTrades(char const, int, long, long, Json::Value&)': example.cpp:(.text+0x25c9): undefined reference to `hmac_sha256[abi:cxx11](char const, char const)' /tmp/ccSoRo3V.o: In function `BinaCPP::get_openOrders(char const, long, Json::Value&)': example.cpp:(.text+0x2c98): undefined reference to hmac_sha256[abi:cxx11](char const*, char const*)' /tmp/ccSoRo3V.o: In functionBinaCPP::get_allOrders(char const, long, int, long, Json::Value&)': example.cpp:(.text+0x3407): undefined reference to `hmac_sha256[abi:cxx11](char const, char const)' /tmp/ccSoRo3V.o: In function `BinaCPP::send_order(char const, char const, char const, char const, double, double, char const, double, double, long, Json::Value&)': example.cpp:(.text+0x3db9): undefined reference to hmac_sha256[abi:cxx11](char const*, char const*)' /tmp/ccSoRo3V.o:example.cpp:(.text+0x44e9): more undefined references tohmac_sha256[abi:cxx11](char const, char const)' follow collect2: error: ld returned 1 exit status Makefile:21: recipe for target 'example' failed make: *** [example] Error 1

Any hint is welcome. thanks much!

rayguang commented 5 years ago

Issues resolved.

recompiled the binacepp from /src.

However, I added the following function back to binance_utils.h to resolve the to_string was not declared in this scope error)

Added the following to binance_utils.h

template inline string to_string (const T& t) { stringstream ss; ss << t; return ss.str(); }

static std::string to_string(double val) { std::ostringstream out; out.precision(8); out.setf(std::ios_base::fixed); out << val; return out.str(); }