Author Topic: Linking .so library  (Read 9796 times)

Offline ValeV

  • Multiple posting newcomer
  • *
  • Posts: 23
Linking .so library
« on: November 19, 2021, 11:07:22 am »
I'm having troubles linking .so library to the project. I got the library from https://github.com/tensaix2j/binacpp.

To the project I added:
Project -> Build Options -> select Release on the left side -> Search Directories -> Compiler -> added "lib\lib\libbinacpp\include"
Project -> Build Options -> select Release on the left side -> Linker Settings -> Link libraries added "lib\lib\libbinacpp\lib\libbinacpp.so"

Then in my code I call
Code
BinaCPP::init(m_apiKey, m_secretKey);
, but get error "undefined reference to BinaCPP::init".

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Linking .so library
« Reply #1 on: November 19, 2021, 11:13:00 am »
Did you compile the library or just downloaded the binary?

Post a full rebuild log

Offline ValeV

  • Multiple posting newcomer
  • *
  • Posts: 23
Re: Linking .so library
« Reply #2 on: November 19, 2021, 11:50:03 am »
I didn't compile, isn't library basically a precompiled code ready to use?

Code
-------------- Clean: Release in AssuringBot (compiler: gnu_gcc_compiler_w64_wxwidgets)---------------

Cleaned "AssuringBot - Release"

-------------- Build: Release in AssuringBot (compiler: gnu_gcc_compiler_w64_wxwidgets)---------------

g++.exe -Wall -std=gnu++11 -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DwxUSE_UNICODE -O2 -IC:\wxWidgets-3.1.2\include -IC:\wxWidgets-3.1.2\lib\gcc_lib\mswu -I"C:\Program Files\OpenSSL-Win64\include" -Ibinance_api\lib\libcurl-7.56.0\include -Ibinance_api\lib\jsoncpp-1.8.3\include -Ibinance_api\lib\libwebsockets-2.4.0\include -Ibinance_api\lib\libbinacpp\include -c C:\Users\M0097932\Desktop\AssuringBot\AssuringBotApp.cpp -o obj\Release\AssuringBotApp.o
g++.exe -Wall -std=gnu++11 -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DwxUSE_UNICODE -O2 -IC:\wxWidgets-3.1.2\include -IC:\wxWidgets-3.1.2\lib\gcc_lib\mswu -I"C:\Program Files\OpenSSL-Win64\include" -Ibinance_api\lib\libcurl-7.56.0\include -Ibinance_api\lib\jsoncpp-1.8.3\include -Ibinance_api\lib\libwebsockets-2.4.0\include -Ibinance_api\lib\libbinacpp\include -c C:\Users\M0097932\Desktop\AssuringBot\AssuringBotMain.cpp -o obj\Release\AssuringBotMain.o
windres.exe -IC:\wxWidgets-3.1.2\include -IC:\wxWidgets-3.1.2\lib\gcc_lib\mswu  -J rc -O coff -i C:\Users\M0097932\Desktop\ASSURI~1\resource.rc -o obj\Release\resource.res
g++.exe -LC:\wxWidgets-3.1.2\lib\gcc_lib -o bin\Release\AssuringBot.exe obj\Release\AssuringBotApp.o obj\Release\AssuringBotMain.o  obj\Release\resource.res -s  -mthreads  -lwxmsw31u_core -lwxbase31u -lwxpng -lwxjpeg -lwxtiff -lwxzlib "C:\Program Files\OpenSSL-Win64\lib\openssl.lib" binance_api\lib\libbinacpp\lib\libbinacpp.so binance_api\lib\libcurl-7.56.0\lib\libcurl.a binance_api\lib\libwebsockets-2.4.0\lib\libwebsockets.a -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 -lwsock32 -lodbc32 -lshlwapi -lversion -loleacc -luxtheme -mwindows
In file included from binance_api\lib\libcurl-7.56.0\include/curl/system.h:389,
                 from binance_api\lib\libcurl-7.56.0\include/curl/curl.h:38,
                 from binance_api\lib\libbinacpp\include/binacpp.h:22,
                 from C:\Users\M0097932\Desktop\AssuringBot\AssuringBotMain.cpp:15:
C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winsock2.h:15:2: warning: #warning Please include winsock2.h before windows.h [-Wcpp]
 #warning Please include winsock2.h before windows.h
  ^~~~~~~
obj\Release\AssuringBotMain.o:AssuringBotMain.cpp:(.text+0x18d1): undefined reference to `BinaCPP::init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 6 second(s))
2 error(s), 1 warning(s) (0 minute(s), 6 second(s))
 

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Linking .so library
« Reply #3 on: November 19, 2021, 12:52:04 pm »
The precompiled libraries are intended to be used with the same compiler that created them, you can not pick a random library and link with it. For added trouble, the .so is a Linux library.

You need to compile the library yourself using the same x86_64-8.1.0-posix-seh-rt_v6-rev0 compiler and the makefile in the src folder

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Linking .so library
« Reply #4 on: November 20, 2021, 12:45:57 am »
.so libraries are for Linux, NOT Windows. On Windows the equivalent is a .DLL.  As you are trying to use the .so on Windows it will NOT work, unless it is a DLL that has a wrong extension.

You will need to rebuild the library from source code to get it to work on Windows, but you will need to create a new makefile or C::B project to do this as the existing makefile is for unix only. It may be easier for you to find another Binance library that is for MINGW or MSYS2 and use it (it will probably need to be built, but should include the relevant files)

Offline ValeV

  • Multiple posting newcomer
  • *
  • Posts: 23
Re: Linking .so library
« Reply #5 on: November 22, 2021, 01:15:51 pm »
Thank you to both. What if I just include .h and .cpp files from folder src? It seems like the files that make the .so library are all there.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Linking .so library
« Reply #6 on: November 22, 2021, 01:47:44 pm »
It may work, just test it. After successful compilation you can get a linker error about libcurl, libjson and libwebsockets, it should be easy to link with them (but, as said before, you should have compiled these libraries yourself).

Offline ValeV

  • Multiple posting newcomer
  • *
  • Posts: 23
Re: Linking .so library
« Reply #7 on: November 22, 2021, 02:03:26 pm »
I use mingw compiler as well, so I think the libraries should work. I will test it and come back with an update. :)