SFML未定义对`sf :: TcpSocket :: TcpSocket()'的引用

时间:2016-10-29 04:11:11

标签: c++ c++11 g++ sfml

我正在尝试编译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;
}

安装了所有libs和依赖项:

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。 谁能知道如何解决它?

1 个答案:

答案 0 :(得分:1)

您正在与graphicssystemwindow进行关联,但未与network进行关联。您是否尝试添加-lsfml-network