Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Linking error only against sfml-network on linux  (Read 3526 times)

0 Members and 1 Guest are viewing this topic.

gelberdaniel19

  • Newbie
  • *
  • Posts: 2
    • View Profile
Linking error only against sfml-network on linux
« on: January 20, 2020, 01:58:58 am »
Hello! I am trying to build a server on Linux and I'm having issues. Everything links properly except some network functions. Here is my minimal example:
#include <SFML/Network.hpp>

int main() {
        sf::Http http("http://127.0.0.1", 8080);
}
 

The code compiles with no issues. When I use GCC to build it without linking, it gives the following output:
g++ main.o -o out
main.o: In function `main':
main.cpp:(.text+0x3e): undefined reference to `sf::Http::Http(std::string const&, unsigned short)'
main.o:(.rodata._ZTIN2sf9TcpSocketE[_ZTIN2sf9TcpSocketE]+0x10): undefined reference to `typeinfo for sf::Socket'
main.o: In function `sf::TcpSocket::~TcpSocket()':
main.cpp:(.text._ZN2sf9TcpSocketD2Ev[_ZN2sf9TcpSocketD5Ev]+0x30): undefined reference to `sf::Socket::~Socket()'
collect2: error: ld returned 1 exit status
 

You might think "well you must link against sfml-network." When I do that, it gives me the following:
g++ main.o -o out -lsfml-network -lsfml-system
main.o: In function `main':
main.cpp:(.text+0x3e): undefined reference to `sf::Http::Http(std::string const&, unsigned short)'
collect2: error: ld returned 1 exit status
 

As you can see, linking against network gives me less linker errors but still one. I have verified that the .so libraries exist in a place that g++ can find, so this makes me believe something might be wrong with the shared object. The same code runs with VC++ just fine.

The odd part is that I can compile and link the following code with no issues:
#include <SFML/Network.hpp>

int main() {
        sf::Packet pack;
        pack.clear();
}
 

That leaves me completely stumped as to why I can't link against sfml-network specifically for Http. If you have any ideas or request more info, let me know! Thank you for your help.

gelberdaniel19

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Linking error only against sfml-network on linux
« Reply #1 on: January 20, 2020, 04:59:00 am »
If anyone is curious, I fixed the issue by using static linkage from an older version. It seems to be an issue with the 2.5.1 build on the website for Linux.

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Linking error only against sfml-network on linux
« Reply #2 on: January 20, 2020, 06:31:09 pm »
Nothing in 2.5.1 changed for that class. My guess is that either your compiler is not actually fully compatible, or you've not installed the package correctly. I suggest rebuilding 2.5.1 yourself instead of using the Linux package. It's just safer for compatibility.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

 

anything