socket.io-client-cpp icon indicating copy to clipboard operation
socket.io-client-cpp copied to clipboard

Undefined reference to sio::client::client()

Open purefan opened this issue 6 years ago • 7 comments

Hello,

I've followed the set up instructions as best as I can, boost seems linked, as well as the socket-io libraries. Following the example my main.cpp looks like this:

#include "./lib/socket.io-client-cpp/src/sio_client.h"
#include "./lib/socket.io-client-cpp/src/sio_socket.h"
#include "./lib/socket.io-client-cpp/src/sio_message.h"

int main(int , char* argv[]) {
    sio::client h;
    h.connect("http://127.0.0.1:3000");
    return 0;
}

The path to sio_client.h is correct, VSCode complained when I pointed to the wrong location, and if I shift+click sio::client it does take me to the header file, but when compiling the following errors show up:

/tmp/ccuONn4Y.o: In function main': /path/to/main.cpp:6: undefined reference to sio::client::client()' /path/to/main.cpp:7: undefined reference to sio::client::connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /path/to/main.cpp:6: undefined reference to sio::client::~client()' /path/to/main.cpp:6: undefined reference to `sio::client::~client()' collect2: error: ld returned 1 exit status Makefile:37: recipe for target 'all' failed

My makefile looks like this:

# All purpose variables
compiler=g++
project_root = ./

#   Where to store the binaries
target_folder=bin
target_bin=louise
source_to_main=src/louise/main.cpp

# Compiler flags
flags=-std=c++11 -Wall -Werror -g -v -lboost_filesystem -lboost_system
deps = ./src/louise/lib/socket.io-client-cpp/sio_client.h ./src/louise/lib/socket.io-client-cpp/lib/websocketpp ./src/louise/lib/socket.io-client-cpp/lib/rapidjson

# Compilation instructions
%.o: %.c $(deps)
	$(CC) -c -o $@ $< $(flags)

all:
	cd $(project_root)
	if [ -a $(target_folder)/${target_bin} ]; then rm $(target_folder)/${target_bin}; fi;

	$(compiler) ${source_to_main} -o $(target_folder)/${target_bin} ${flags}

I realize an ld error is a linker error, but cant spot what's wrong in my setup, a little help please?

purefan avatar Sep 20 '17 05:09 purefan

Made some progress, realized I was missing the client sources in my Makefile, which now looks like this:

# All purpose variables
compiler=g++
project_root = ./

#   Where to store the binaries
target_folder=bin
target_bin=louise
source_to_main=src/louise/main.cpp src/louise/lib/socket.io-client-cpp/src/sio_client.cpp src/louise/lib/socket.io-client-cpp/src/sio_socket.cpp

flags=-std=c++11 -Wall -Werror -g -v -lboost_filesystem -lboost_system
deps = ./src/louise/lib/socket.io-client-cpp/sio_client.h ./src/louise/lib/socket.io-client-cpp/lib/websocketpp ./src/louise/lib/socket.io-client-cpp/lib/rapidjson

...
$(compiler) ${source_to_main} -o $(target_folder)/${target_bin} ${flags}

The current error Im getting is:

src/louise/lib/socket.io-client-cpp/src/internal/sio_client_impl.h:15:34: fatal error: websocketpp/client.hpp: No such file or directory

purefan avatar Sep 20 '17 07:09 purefan

Hey, I am getting the same error. Have you solve the problem? fatal error: websocketpp/client.hpp: No such file or directory.

ShivankGupta avatar Nov 28 '17 14:11 ShivankGupta

@ShivankGupta https://github.com/socketio/socket.io-client-cpp/issues/94

And updating websocket git (replace everything in socket.io-client-cpp\lib\websocketpp and rebuild libraries) would solve other problems with working with outdated libraries

AntumArk avatar Aug 07 '18 11:08 AntumArk

Hello, was this resolved ? @purefan @shivankgupta

alter-sachin avatar Sep 22 '19 07:09 alter-sachin

Sorry guys, no fix on my end, I eventually moved to another programming language for websockets

purefan avatar Sep 23 '19 15:09 purefan

same here qt project, can not compile

image

Sun1ive avatar Dec 07 '19 17:12 Sun1ive

Adding -L. -lsioclient resolved sio::client::client() related issue for me. But now getting below error on Ubuntu 18.04:

client1.cpp:(.text+0x12e): undefined reference to 'sio::client::connect(std::string const&)'
client1.cpp:(.text+0x182): undefined reference to 'sio::client::socket(std::string const&)'
client1.cpp:(.text+0x1ef): undefined reference to 'sio::socket::emit(std::string const&, sio::message::list const&, std::function<void (sio::message::list const&)> const&)'
collect2: error: ld returned 1 exit status

archanabwk avatar Dec 23 '21 08:12 archanabwk