binance-exchange / binacpp

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

to_string(double&) is ambiguous #21

Closed AlconDivino closed 6 years ago

AlconDivino commented 6 years ago

Pretty much the Title. When compiling i get the error

Call of overloaded 'to_string(double&)* is ambiguos'

from binacpp.h.

Using Win64 and Codeblocks.

Any suggestions?

alexanderkoumis commented 6 years ago

See this discussion:

https://discuss.codechef.com/questions/87478/to_string-function-in-codeblock-not-wrorking

Chances are:

AlconDivino commented 6 years ago

Thank you i seriously forgot to set the Flag 🤦‍♂️

But i got another issue. I Included everything and also linked every library. Why do i get the Error

undefined reference to `BinaCPP::init(std::cxx11::basic_string<char, std::char_traits, std::allocator >&, std::cxx11::basic_string<char, std::char_traits, std::allocator >&)'|

I can't seem to understand it :/

EDIT: I didn't want to start a new issue here :D

alexanderkoumis commented 6 years ago

Did you compile binacpp as a separate library and link that to your own program? Or did you try to compile your program along with all of the binacpp sources?

AlconDivino commented 6 years ago

tried to compile binacpp seperatly and still getting that ambigous error image

Any idea?

alexanderkoumis commented 6 years ago

I'm guessing it has something to do with spotty support for to_string on MinGW's side. You can try implementing this patch for now (found here):

#include <string>
#include <sstream>

namespace patch
{
    template < typename T > std::string to_string( const T& n )
    {
        std::ostringstream stm ;
        stm << n ;
        return stm.str() ;
    }
}

#include <iostream>

int main()
{
    std::cout << patch::to_string(1234) << '\n' << patch::to_string(1234.56) << '\n' ;
}

You will have to add the patch:: namespace to all the calls that fail to make sure your modified version is called. Or do a search and replace in Codeblocks to replace all to_string calls to patch::to_string.

AlconDivino commented 6 years ago

Thanks :D

AlconDivino commented 6 years ago

No does not work. On Stack overflow i was told to reopen the issue.

I still cannot compile the Library for my system because apparently the using namespace std statement is causing the ambigous problem. any idea?

when running make in terminal i get following errormessages in terminal:

pi@raspberrypi:~/Desktop/patch/src $ make g++ -I../lib/libcurl-7.56.0/include -I../lib/jsoncpp-1.8.3/include -c binacpp.cpp -fPIC -o ../lib/libbinacpp/lib/binacpp.o binacpp.cpp: In static member function ‘static void BinaCPP::send_order(const char*, const char*, const char*, const char*, double, double, const char*, double, double, long int, Json::Value&)’: binacpp.cpp:909:39: error: call of overloaded ‘to_string(double&)’ is ambiguous post_data.append( to_string( quantity) ); ^ In file included from binacpp.cpp:16:0: binacpp_utils.h:28:15: note: candidate: std::__cxx11::string to_string(const T&) [with T = double; std::__cxx11::string = std::__cxx11::basic_string<char>] inline string to_string (const T& t) ^~~~~~~~~ binacpp_utils.h:36:20: note: candidate: std::__cxx11::string to_string(double) static std::string to_string(double val) ^~~~~~~~~ In file included from /usr/include/c++/6/string:52:0, from /usr/include/c++/6/bits/locale_classes.h:40, from /usr/include/c++/6/bits/ios_base.h:41, from /usr/include/c++/6/ios:42, from /usr/include/c++/6/ostream:38, from /usr/include/c++/6/iostream:39, from binacpp.h:19, from binacpp.cpp:14: /usr/include/c++/6/bits/basic_string.h:5522:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long double) to_string(long double __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5513:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(double) to_string(double __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5504:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(float) to_string(float __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5498:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long unsigned int) to_string(unsigned long long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5492:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long int) to_string(long long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5486:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long unsigned int) to_string(unsigned long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5481:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long int) to_string(long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5475:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(unsigned int) to_string(unsigned __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5470:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(int) to_string(int __val) ^~~~~~~~~ binacpp.cpp:912:36: error: call of overloaded ‘to_string(double&)’ is ambiguous post_data.append( to_string( price) ); ^ In file included from binacpp.cpp:16:0: binacpp_utils.h:28:15: note: candidate: std::__cxx11::string to_string(const T&) [with T = double; std::__cxx11::string = std::__cxx11::basic_string<char>] inline string to_string (const T& t) ^~~~~~~~~ binacpp_utils.h:36:20: note: candidate: std::__cxx11::string to_string(double) static std::string to_string(double val) ^~~~~~~~~ In file included from /usr/include/c++/6/string:52:0, from /usr/include/c++/6/bits/locale_classes.h:40, from /usr/include/c++/6/bits/ios_base.h:41, from /usr/include/c++/6/ios:42, from /usr/include/c++/6/ostream:38, from /usr/include/c++/6/iostream:39, from binacpp.h:19, from binacpp.cpp:14: /usr/include/c++/6/bits/basic_string.h:5522:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long double) to_string(long double __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5513:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(double) to_string(double __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5504:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(float) to_string(float __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5498:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long unsigned int) to_string(unsigned long long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5492:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long int) to_string(long long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5486:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long unsigned int) to_string(unsigned long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5481:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long int) to_string(long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5475:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(unsigned int) to_string(unsigned __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5470:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(int) to_string(int __val) ^~~~~~~~~ binacpp.cpp:921:42: error: call of overloaded ‘to_string(double&)’ is ambiguous post_data.append( to_string( stopPrice ) ); ^ In file included from binacpp.cpp:16:0: binacpp_utils.h:28:15: note: candidate: std::__cxx11::string to_string(const T&) [with T = double; std::__cxx11::string = std::__cxx11::basic_string<char>] inline string to_string (const T& t) ^~~~~~~~~ binacpp_utils.h:36:20: note: candidate: std::__cxx11::string to_string(double) static std::string to_string(double val) ^~~~~~~~~ In file included from /usr/include/c++/6/string:52:0, from /usr/include/c++/6/bits/locale_classes.h:40, from /usr/include/c++/6/bits/ios_base.h:41, from /usr/include/c++/6/ios:42, from /usr/include/c++/6/ostream:38, from /usr/include/c++/6/iostream:39, from binacpp.h:19, from binacpp.cpp:14: /usr/include/c++/6/bits/basic_string.h:5522:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long double) to_string(long double __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5513:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(double) to_string(double __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5504:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(float) to_string(float __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5498:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long unsigned int) to_string(unsigned long long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5492:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long int) to_string(long long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5486:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long unsigned int) to_string(unsigned long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5481:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long int) to_string(long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5475:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(unsigned int) to_string(unsigned __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5470:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(int) to_string(int __val) ^~~~~~~~~ binacpp.cpp:926:43: error: call of overloaded ‘to_string(double&)’ is ambiguous post_data.append( to_string( icebergQty ) ); ^ In file included from binacpp.cpp:16:0: binacpp_utils.h:28:15: note: candidate: std::__cxx11::string to_string(const T&) [with T = double; std::__cxx11::string = std::__cxx11::basic_string<char>] inline string to_string (const T& t) ^~~~~~~~~ binacpp_utils.h:36:20: note: candidate: std::__cxx11::string to_string(double) static std::string to_string(double val) ^~~~~~~~~ In file included from /usr/include/c++/6/string:52:0, from /usr/include/c++/6/bits/locale_classes.h:40, from /usr/include/c++/6/bits/ios_base.h:41, from /usr/include/c++/6/ios:42, from /usr/include/c++/6/ostream:38, from /usr/include/c++/6/iostream:39, from binacpp.h:19, from binacpp.cpp:14: /usr/include/c++/6/bits/basic_string.h:5522:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long double) to_string(long double __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5513:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(double) to_string(double __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5504:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(float) to_string(float __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5498:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long unsigned int) to_string(unsigned long long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5492:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long int) to_string(long long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5486:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long unsigned int) to_string(unsigned long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5481:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long int) to_string(long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5475:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(unsigned int) to_string(unsigned __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5470:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(int) to_string(int __val) ^~~~~~~~~ binacpp.cpp: In static member function ‘static void BinaCPP::withdraw(const char*, const char*, const char*, double, const char*, long int, Json::Value&)’: binacpp.cpp:1384:38: error: call of overloaded ‘to_string(double&)’ is ambiguous post_data.append( to_string( amount )); ^ In file included from binacpp.cpp:16:0: binacpp_utils.h:28:15: note: candidate: std::__cxx11::string to_string(const T&) [with T = double; std::__cxx11::string = std::__cxx11::basic_string<char>] inline string to_string (const T& t) ^~~~~~~~~ binacpp_utils.h:36:20: note: candidate: std::__cxx11::string to_string(double) static std::string to_string(double val) ^~~~~~~~~ In file included from /usr/include/c++/6/string:52:0, from /usr/include/c++/6/bits/locale_classes.h:40, from /usr/include/c++/6/bits/ios_base.h:41, from /usr/include/c++/6/ios:42, from /usr/include/c++/6/ostream:38, from /usr/include/c++/6/iostream:39, from binacpp.h:19, from binacpp.cpp:14: /usr/include/c++/6/bits/basic_string.h:5522:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long double) to_string(long double __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5513:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(double) to_string(double __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5504:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(float) to_string(float __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5498:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long unsigned int) to_string(unsigned long long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5492:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long int) to_string(long long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5486:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long unsigned int) to_string(unsigned long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5481:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long int) to_string(long __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5475:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(unsigned int) to_string(unsigned __val) ^~~~~~~~~ /usr/include/c++/6/bits/basic_string.h:5470:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(int) to_string(int __val) ^~~~~~~~~ Makefile:38: recipe for target '../lib/libbinacpp/lib/binacpp.o' failed make: *** [../lib/libbinacpp/lib/binacpp.o] Error 1

Any ideas?

Also i am using rasbian on a raspberry pi and Code::blocks IDE

alexanderkoumis commented 6 years ago

You are right. The most recent few commits from @tensaix2j are causing these problems, the project no longer compiles on my machine as well. Most likely 2c03cb22 is the culprit.

alexanderkoumis commented 6 years ago

I am running on a standard x86_64 OSX platform.

alexanderkoumis commented 6 years ago

Looks like @tensaix2j was trying to use the same hack I mentioned above. This is caused by the addition of another to_string function in binacpp_utils.h. Because the new to_string is not in a namespace, and using namespace std is being used, we get this error. I added the std:: prefix to all usages of to_string in binacpp.cpp to avoid using the hack version and it compiled fine.

pndiaye commented 6 years ago

I confirm, prepending std:: to all the calls to to_string does the work, at least on OSX.

AlconDivino commented 6 years ago

when i type std::to_string() no suggestion pops up will it work ?

AlconDivino commented 6 years ago

I now changed everything to std::to_string

Going to console and running make clean and make

Now i get a lot of notes saying parameter passing for argument of type ... will chanfe in GCC 7.1 and at the end failing compilation of libbinacpp.so

Any ideas? i'm pretty deperate rn

alexanderkoumis commented 6 years ago

That’s not an error is it? That looks like a warning. You need to show us the actual error message.

AlconDivino commented 6 years ago

ah now i get it the actual problem is that it doesn't recognize the libcurl.so fileformat.

I guess its because i use rasbian for raspberry pi .

Any idea how i can compile libcurl for my raspberry ?

pndiaye commented 6 years ago

This question doesn't belong in this thread but just for info: You'll probably have to compile openssl (a dependency of libcurl), libcurl, jsoncpp and libwebsockets. You can clone them from their github repo and can definitely find the compilation instructions for your platform there or on other threads more specific to them

AlconDivino commented 6 years ago

So i got another issue but i think this will be too much fpor this thread so i'll open another one

Thank you guys