I can compile a program that uses only semaphores or one that uses only the sio_client websocket library. However, when compiling a simple program that contains both libraries, I deal with gigantic compilation problems that I don't even know how to describe.
#include <iostream>
#include <thread>
#include <chrono>
// #include <sio_client.h>
#include "socket.io-client-cpp/src/sio_client.h"
#include <semaphore>
using namespace sio;
using namespace std;
sio::client io;
counting_semaphore<1>* test;
//g++-11 main.cpp -std=c++17 -o app -L /usr/local/lib -l sioclient -I /usr/local/include
void OnMessage(sio::event &m){
auto messages = m.get_messages();
io.socket()->emit("key", string("Hello"));
test->release();
}
int main()
{
sio::client io;
io.connect("http://127.0.0.1:8081");
string command = "w";
test = new counting_semaphore<1>(0);
io.socket()->on("teste", &OnMessage);
while(true){
test->acquire();
cout << " :D " << endl;
this_thread::sleep_for(100ms);
}
}
If I replace the include "socket.io-client-cpp/src/sio_client.h" by <sio_client.h> the compiler does not find the sio_client library, and if I include the library path manually, as it is in the code, the error is bigger than the bible.
It is important to point out that I did the sio_client installation process according to the README.md included in the library itself and I have already used it in other contexts, which worked perfectly.
To compile this program I'm using the following command:
g++-11 main.cpp -std=c++2a -L. -lsioclient -o app
beginning of errors:
ld: warning: dylib (/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11/libstdc++.dylib) was built for newer macOS version (11.3) than being linked (11.1)
Undefined symbols for architecture x86_64:
"__ZN3sio6client6socketERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", referenced from:
__Z9OnMessageRN3sio5eventE in ccKuChIE.o
_main in ccKuChIE.o
"__ZN3sio6client7connectERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", referenced from:
_main in ccKuChIE.o
"__ZN3sio6socket2onERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt8functionIFvRNS_5eventEEE", referenced from:
_main in ccKuChIE.o
"__ZN3sio6socket4emitERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_7message4listERKSt8functionIFvSC_EE", referenced from:
__Z9OnMessageRN3sio5eventE in ccKuChIE.o
"__ZNKSt3__110error_code7messageEv", referenced from:
__ZN11websocketpp9transport4asio8endpointINS_6config11asio_client16transport_configEE9init_asioEv in libsioclient.a(sio_client_impl.cpp.o)
__ZN3sio11client_impl12connect_implERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_ in libsioclient.a(sio_client_impl.cpp.o)
__ZN11websocketpp10connectionINS_6config11asio_clientEE14replace_headerERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEESC_ in libsioclient.a(sio_client_impl.cpp.o)
__ZN3sio11client_impl9send_implERKNSt3__110shared_ptrIKNS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEEN11websocketpp5frame6opcode5valueE in libsioclient.a(sio_client_impl.cpp.o)
__ZN11websocketpp9exceptionC1ENSt3__110error_codeE in libsioclient.a(sio_client_impl.cpp.o)
__ZN11websocketpp8endpointINS_10connectionINS_6config11asio_clientEEES3_E17create_connectionEv in libsioclient.a(sio_client_impl.cpp.o)
__ZN11websocketpp10connectionINS_6config11asio_clientEE17handle_read_frameERKNSt3__110error_codeEm in libsioclient.a(sio_client_impl.cpp.o)
...
"__ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE13find_first_ofEPKcmm", referenced from:
__ZN3sio6packet5parseERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE in libsioclient.a(sio_packet.cpp.o)
"__ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4findEcm", referenced from:
__ZN3sio11client_impl12connect_implERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_ in libsioclient.a(sio_client_impl.cpp.o)
__ZN3sio6packet5parseERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE in libsioclient.a(sio_packet.cpp.o)
"__ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7compareEmmPKcm", referenced from:
__ZN3sio11client_impl12connect_implERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_ in libsioclient.a(sio_client_impl.cpp.o)
__ZN3sio11client_impl6socketERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE in libsioclient.a(sio_client_impl.cpp.o)
__ZN11websocketpp4http6parser6parser12prepare_bodyEv in libsioclient.a(sio_client_impl.cpp.o)
__ZN11websocketpp3uriC2ENSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERKS7_S9_ in libsioclient.a(sio_client_impl.cpp.o)
__ZN11websocketpp3uriC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_S9_S9_ in libsioclient.a(sio_client_impl.cpp.o)
__ZNK11websocketpp9processor6hybi00INS_6config11asio_clientEE18validate_handshakeERKNS_4http6parser7requestE in libsioclient.a(sio_client_impl.cpp.o)
__ZNK11websocketpp9processor6hybi13INS_6config11asio_clientEE18validate_handshakeERKNS_4http6parser7requestE in libsioclient.a(sio_client_impl.cpp.o)
...