niXman / binapi

Binance API C++ implementation
Apache License 2.0
264 stars 88 forks source link

Windows version #7

Closed klemenpeganc closed 3 years ago

klemenpeganc commented 3 years ago

Hi, any chance you could provide the changes needed to compile this on windows?

niXman commented 3 years ago

hi,

I have not tried to compile this code for windows, but I think there should be no problems because there is nothing platform-dependent in the code...

klemenpeganc commented 3 years ago

Hi, thanks for your answer. The problem occurs when linking additional libraries: target_link_libraries( ${PROJECT_NAME} z crypto ssl pthread )

What would the windows equivalent be of this?

niXman commented 3 years ago

z - zlib crypto and ssl - openssl pthread - just ignore it

klemenpeganc commented 3 years ago

this worked, I managed to get it to build. However, now every API function call results in: can't dereference value-initialized vector iterator

Call stack: image

niXman commented 3 years ago

hmm... could you provide me the sample code that leads to this error?

klemenpeganc commented 3 years ago
binapi::rest::api api(
         ioctx
        ,"api.binance.com"
        ,"443"
        , API_KEY
        , PRIVATE_KEY
        ,10000
    );

auto server_time = api.server_time();

It crashes in flatjson.hpp, line 1451: m_end = &(*m_storage->end()); Contents of m_storage: image

This is the state just before line 1451 is executed.

niXman commented 3 years ago

which compiler are you using?

klemenpeganc commented 3 years ago

MSVC 19.22.27905.0

niXman commented 3 years ago

I don't have access to the Windows machine, but I'll try to figure it out...

klemenpeganc commented 3 years ago

Thanks, appreciate it! I will try using Clang in the meantime. I will let you know how it goes

klemenpeganc commented 3 years ago

Just wanted to let you know, that it fully works using MSVC in Release mode.

niXman commented 3 years ago

fixed: https://github.com/niXman/flatjson/commit/617d4cbaf6b1aea1e1ec47a1799952f8197dccb4

please confirm.

repane4229 commented 3 years ago

@klemenpeganc can you let me know how you built this on windows with setting up all the libs? Thanks

klemenpeganc commented 3 years ago

I used vcpkg for the libraries and my CMakeLists.txt file looks like this:


project(binapi)

set(CMAKE_CXX_STANDARD 14)
include(path/to/vcpkg.cmake)
find_package(ZLIB REQUIRED)
find_package(OpenSSL REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
add_definitions(
    -UNDEBUG
    -DDTF_HEADER_ONLY
    -D__FLATJSON__CHILDS_TYPE=std::uint32_t
    -D__FLATJSON__VLEN_TYPE=std::uint32_t
)

include_directories(
    ./include
)

include_directories("path/to/boost/folder")
link_directories("path/to/boost/libs")

set(BINAPI_HEADERS
    binapi/api.hpp
    binapi/flatjson.hpp
    binapi/dtf.hpp
    binapi/double_type.hpp
    binapi/invoker.hpp
    binapi/io_state.hpp
    binapi/message.hpp
    binapi/pairslist.hpp
    binapi/reports.hpp
    binapi/tools.hpp
    binapi/types.hpp
    binapi/websocket.hpp
)

set(BINAPI_SOURCES
    src/api.cpp
    src/io_state.cpp
    src/pairslist.cpp
    src/reports.cpp
    src/tools.cpp
    src/types.cpp
    src/websocket.cpp
)

add_executable(
    ${PROJECT_NAME}
    #
    main.cpp
    #
    ${BINAPI_SOURCES}
)

target_link_libraries(
    ${PROJECT_NAME}
    ZLIB::ZLIB
    OpenSSL::SSL
   OpenSSL::Crypto
)