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

Author Topic: sf::IpAddress:toString() not working  (Read 2563 times)

0 Members and 1 Guest are viewing this topic.

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
sf::IpAddress:toString() not working
« on: July 01, 2015, 02:45:13 pm »
I've made sfml from source (a two month old version of 2.3)  to work with MinGW 5.1.0 (with -std=c++14) with codeblocks on windows 8.1 and all network functions that I've tried work fine, except sf::IpAddress::toString(). This is my code:
#include <iostream>
#include <string>

#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(600,600), "Long distance pong");
    sf::IpAddress address(sf::IpAddress::getLocalAddress());
    std::cout<<address.toString()<<std::endl;
    std::cin.get();
    sf::TcpSocket socket;
    //sf::Socket::Status = socket.connect("");
    sf::sleep(sf::milliseconds(1000));
}
 
It keeps coming up with undefined reference to sf::IpAddress::toString[abi:cxx11]() const. I don't think it can be a problem with my linking as I've checked it loads of times, CMake didn't come up with any errors while I was building and no other errors or warnings are being produced (with -Wall on). Does anyone know why this one function isn't working?

I found that function in the repository and replaced my code (above) with this
#include <iostream>
#include <string>
#include <windows.h>

#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>

int main()
{
    sf::IpAddress address(sf::IpAddress::getLocalAddress());
    in_addr addr;
    addr.s_addr = address.toInteger();
    std::cout<<inet_ntoa(addr)<<std::endl;
    std::cin.get();
}
 
and it works, but I would prefer to use the SFML function.
« Last Edit: July 01, 2015, 06:32:00 pm by shadowmouse »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: sf::IpAddress:toString() not working
« Reply #1 on: July 01, 2015, 07:33:52 pm »
It keeps coming up with undefined reference to sf::IpAddress::toString[abi:cxx11]() const.
Sounds like you compiled SFML for C++11 while compiling your application for C++14. Make sure to add the -std=c++14 flag in the CMake advanced options.

Also, you should always provide the full error and not just excerpts.

The reason you get the error is because the C++11 ABI and C++14 ABI in GCC 5.1 are probably not compatible.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: sf::IpAddress:toString() not working
« Reply #2 on: July 01, 2015, 07:48:29 pm »
It runs now, thanks, though the command prompt came up with something about auto_ptr when I was running mingw32-make. It was probably referring to the std::auto_ptr<AudioDevice> in AudioDevice.cpp. It's surprising that there are still those in there.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: sf::IpAddress:toString() not working
« Reply #3 on: July 01, 2015, 07:51:18 pm »
Well auto_ptr is C++03 which is the version SFML is using, while all the other smart pointers were only introduced in C++11. Since auto_ptr is now deprecated a compiler may return a warning, but it's nothing to worry about. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/