SFML 未定义对“sf::TcpSocket::TcpSocket()”的引用

SFML undefined reference to `sf::TcpSocket::TcpSocket()'

我正在尝试编译 SFML 简单代码:

#include <iostream>
#include <string>
#include <SFML/System.hpp>
#include <SFML/Network.hpp>

using namespace std;

int main(int argc, char* argv[])
{

    sf::TcpSocket socket;
    sf::Socket::Status status = socket.connect("127.0.0.1", 6000);
    if (status != sf::Socket::Done)
    {
        // error...
    }
    return 0;
}

已安装所有库和依赖项:

sudo apt-get install libsfml-dev
sudo apt-get build-dep libsfml

我正在使用两种方法:

g++ -c main.cpp
g++ -o main main.o -std=c++11 -lsfml-graphics -lsfml-window -lsfml-system

g++ -c main.cpp -I/home/x64joxer/SFML-2.4.0/include
g++ -o main main.o -L/home/x64joxer/SFML-2.4.0/lib -std=c++11 -lsfml-graphics -lsfml-window -lsfml-system

但我仍然遇到同样的问题:

main.o: In function `main':
main.cpp:(.text+0x27): undefined reference to `sf::TcpSocket::TcpSocket()'
main.cpp:(.text+0x38): undefined reference to `sf::IpAddress::IpAddress(char const*)'
main.cpp:(.text+0x54): undefined reference to `sf::TcpSocket::connect(sf::IpAddress const&, unsigned short, sf::Time)'
main.o: In function `sf::TcpSocket::~TcpSocket()':
main.cpp:(.text._ZN2sf9TcpSocketD2Ev[_ZN2sf9TcpSocketD5Ev]+0x30): undefined reference to `sf::Socket::~Socket()'
main.cpp:(.text._ZN2sf9TcpSocketD2Ev[_ZN2sf9TcpSocketD5Ev]+0x56): undefined reference to `sf::Socket::~Socket()'
main.o:(.rodata._ZTIN2sf9TcpSocketE[_ZTIN2sf9TcpSocketE]+0x10): undefined reference to `typeinfo for sf::Socket'
collect2: error: ld returned 1 exit status

我在论坛上看了很多教程和主题,但我仍然不知道如何解决它。 我的系统是 Kubntu 15。 任何人都可以知道如何解决它吗?

您正在链接 graphicssystemwindow,但未链接 network。您尝试添加 -lsfml-network 了吗?