Hi everyone!
My OS: Ubuntu 18.04
SFML version: 2.5.1
Firstly I want to write that maybe it isn't a problem of SFML, but my research has shown that SFML influences linker.
Code (this may not be right, but it doesn't matter in the context of this problem):
#include <SFML/Network.hpp>
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
int main()
{
sf::TcpSocket socket;
sf::TcpListener socketListen;
if (socketListen.listen(53000) != sf::Socket::Done)
{
std::cerr<<"Error while connecting to port\nAborted.";
return 1;
}
if (socketListen.accept(socket) != sf::Socket::Done)
{
std::cerr<<"Error while accepting\nAborted.";
return 1;
}
sf::Packet packet;
std::string message = "Hi! Welcome to my server. I hope you'll enjoy it.";
packet<<message;
socket.send(packet);
socket.receive(packet);
packet>>message;
std::cout<<message;
return 0;
}
Ok, I can compile it without warnings and errors. I use the follow options:
g++ -std=c++17 -o networkingS -I/home/name/SFML-2.5.1/include -L/home/name/SFML-2.5.1/lib -Wl,-rpath=/home/name/SFML-2.5.1/lib networking.cpp -lsfml-network -lsfml-system -lsfml-graphics
Then I tried to start the program and I got output:
./networkingS: error while loading shared libraries: libsfml-system.so.2.5: cannot open shared object file: No such file or directory
Ok, I used ldd:
linux-vdso.so.1 (0x00007ffc239ce000)
libsfml-graphics.so.2.5 => /home/name/SFML-2.5.1/lib/libsfml-graphics.so.2.5 (0x00007f5dbfa98000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5dbf6a7000)
libsfml-system.so.2.5 => not found
We can see that linker can find path to the graphics module, but can't do it for the system module (and window too, as I have known later)
Ok, I thought "It's environmental problem, but stop, all my applications that use RenderWindow work well!"
I used ldd for them and I got perfect output
linux-vdso.so.1 (0x00007fffb99fe000)
libsfml-graphics.so.2.5 => /home/name/SFML-2.5.1/lib/libsfml-graphics.so.2.5 (0x00007f08d885c000)
libsfml-window.so.2.5 => /home/name/SFML-2.5.1/lib/libsfml-window.so.2.5 (0x00007f08d8633000)
libsfml-system.so.2.5 => /home/name/SFML-2.5.1/lib/libsfml-system.so.2.5 (0x00007f08d8427000)
I'm stuck and don't know what to do with this.
I also tried to use LD_LIBRARY_PATH and it helped me, but I want to know, why some my applications work without setting LD_... and other can't do it.
P.S. sorry if there are grammar mistakes, English isn't my native language.
UPD: I don't know why, but this code works:
#include <SFML/Network.hpp>
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
int main()
{
sf::TcpSocket socket;
sf::Socket::Status status = socket.connect("127.0.0.1", 53000);
if (status != sf::Socket::Done)
{
std::cerr<<"Error while connecting.\nAborted.\n";
return 1;
}
sf::Packet packet;
std::string message;
socket.receive(packet);
packet>>message;
std::cout<<message;
std::cin>>message;
packet.clear();
packet<<message;
socket.send(packet);
return 0;
}
Oh, I forgot to give ldd output of code above:
libsfml-network.so.2.5 => /home/name/SFML-2.5.1/lib/libsfml-network.so.2.5 (0x00007fefb6d62000)
libsfml-system.so.2.5 => /home/name/SFML-2.5.1/lib/libsfml-system.so.2.5 (0x00007fefb6b56000)
It's becoming more complicated for me...