I keep getting errors when compiling a C++ project using SFML 2 on Windows using MinGW.
At C:\MinGW\include\
there is the SFML header files folder including Network.hpp
and I also copied the libsfml-[...].a
files into C:\MinGW\lib\
as well as the sfml-[...]-2.dll
files into C:\MinGW\bin\
.
This is my sample file:
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Network.hpp>
int main(int argc, char** argv)
{
sf::TcpListener listener;
listener.listen(4444);
sf::TcpSocket client;
std::cout << "Waiting for client to connect..." << std::endl;
if (listener.accept(client) == sf::Socket::Done)
{
std::cout << "Client connected: " << client.getRemoteAddress() << std::endl;
listener.close();
}
else
{
std::cout << "Client didnt connect" << std::endl;
}
return 0;
}
If I try to compile it using the following command
g++ test.cpp -lsfml-system -lsfml-network
I get these errors:
C:\Users\me\AppData\Local\Temp\cc6XzH1R.o:test.cpp:(.text+0x28): undefined reference to `_imp___ZN2sf9IpAddress3AnyE`
C:\Users\me\AppData\Local\Temp\cc6XzH1R.o:test.cpp:(.text+0x3a): undefined reference to `_imp___ZN2sf11TcpListener6listenEtRKNS_9IpAddressE`
Thanks for any help :D
Matze
Simple , try to link correct version of library. If you are making x86 app use the 32bit version of library and if you are making x64 app use 64bit version. I also got the same error and this fixed.