SFML网络错误:链接时未定义的引用des

时间:2015-03-06 23:26:34

标签: c++ networking codeblocks sfml mingw32

我最近开始学习SFML,但是当我进入网络部分时,我总是遇到很多错误:

obj\Release\main.o:main.cpp:(.text$_ZN2sf11TcpListenerD1Ev[__ZN2sf11TcpListenerD1Ev]+0x1): undefined reference to `_imp___ZTVN2sf11TcpListenerE'
obj\Release\main.o:main.cpp:(.text$_ZN2sf11TcpListenerD1Ev[__ZN2sf11TcpListenerD1Ev]+0xb): undefined reference to `_imp___ZN2sf6SocketD2Ev'
obj\Release\main.o:main.cpp:(.text$_ZN2sf9TcpSocketD1Ev[__ZN2sf9TcpSocketD1Ev]+0x1): undefined reference to `_imp___ZTVN2sf9TcpSocketE'
obj\Release\main.o:main.cpp:(.text$_ZN2sf9TcpSocketD1Ev[__ZN2sf9TcpSocketD1Ev]+0x25): undefined reference to `_imp___ZN2sf6SocketD2Ev'
obj\Release\main.o:main.cpp:(.text$_ZN2sf9TcpSocketD1Ev[__ZN2sf9TcpSocketD1Ev]+0x2f): undefined reference to `_imp___ZN2sf6SocketD2Ev'
obj\Release\main.o:main.cpp:(.text$_ZN2sf11TcpListenerD0Ev[__ZN2sf11TcpListenerD0Ev]+0x7): undefined reference to `_imp___ZTVN2sf11TcpListenerE'
obj\Release\main.o:main.cpp:(.text$_ZN2sf11TcpListenerD0Ev[__ZN2sf11TcpListenerD0Ev]+0x12): undefined reference to `_imp___ZN2sf6SocketD2Ev'
obj\Release\main.o:main.cpp:(.text$_ZN2sf9TcpSocketD0Ev[__ZN2sf9TcpSocketD0Ev]+0x7): undefined reference to `_imp___ZTVN2sf9TcpSocketE'
obj\Release\main.o:main.cpp:(.text$_ZN2sf9TcpSocketD0Ev[__ZN2sf9TcpSocketD0Ev]+0x23): undefined reference to `_imp___ZN2sf6SocketD2Ev'
obj\Release\main.o:main.cpp:(.text.startup+0x60): undefined reference to `_imp___ZN2sf9IpAddress15getLocalAddressEv'
obj\Release\main.o:main.cpp:(.text.startup+0x72): undefined reference to `_imp___ZN2sf9TcpSocketC1Ev'
obj\Release\main.o:main.cpp:(.text.startup+0x129): undefined reference to `_imp___ZN2sf9TcpSocket4sendEPKvj'
obj\Release\main.o:main.cpp:(.text.startup+0x159): undefined reference to `_imp___ZN2sf9TcpSocket7receiveEPvjRj'
obj\Release\main.o:main.cpp:(.text.startup+0x1f7): undefined reference to `_imp___ZN2sf9TcpSocket7connectERKNS_9IpAddressEtNS_4TimeE'
obj\Release\main.o:main.cpp:(.text.startup+0x226): undefined reference to `_imp___ZN2sf11TcpListenerC1Ev'
obj\Release\main.o:main.cpp:(.text.startup+0x243): undefined reference to `_imp___ZN2sf11TcpListener6listenEt'
obj\Release\main.o:main.cpp:(.text.startup+0x259): undefined reference to `_imp___ZN2sf11TcpListener6acceptERNS_9TcpSocketE'

我正在使用CodeBlocks,编译器参数是:

mingw32-g++.exe -LC:\Users\Justin\AppData\Roaming\CodeBlocks\SFML-2.2\lib -o "bin\Release\SFML Test.exe" obj\Release\main.o  -s  -lsfml-graphics -lsfml-window -lsfml-system

这只发生在我使用网络功能时,没有别的(但我没有尝试过音频)。

提前致谢。

编辑:这是我的代码:

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
using namespace sf;

#include <iostream>
#include <string>

#define cout std::cout
#define endl std::endl

int main(){
    IpAddress ip = IpAddress::getLocalAddress();
    TcpSocket socket;
    char connectionType, mode;
    char buffer[2000];
    std::size_t recieved;
    std::string text = "Connected to: ";

    cout << "Enter (s) for server; Enter (c) for client: ";
    std::cin >> connectionType;

    if(connectionType == 's'){
        TcpListener listener;
        listener.listen(123456);
        listener.accept(socket);
        text += "Server";
    }else if(connectionType == 'c'){
        socket.connect(ip, 123456);
        text += "Client";
    }else{
        cout << "ERROR: Wrong Connection Type";
    }

    socket.send(text.c_str(), text.length());

    socket.receive(buffer, sizeof(buffer), recieved);

    cout << buffer << endl;

    system("pause");
}

1 个答案:

答案 0 :(得分:1)

与网络模块链接:

 mingw32-g++.exe -LC:\Users\Justin\AppData\Roaming\CodeBlocks\SFML-2.2\lib -o "bin\Release\SFML Test.exe" obj\Release\main.o  -s  -lsfml-graphics -lsfml-window -lsfml-system -lsfml-network