So I am trying to write some network related code, specifically a port scanner using SFML. I am running VS 2017 and have downloaded the SFML build for 2015 however people have said this should work with 2017.
My demo code so far to try and see if the library is working is:
#include <iostream>
#include <SFML/Network.hpp>
#include <string>
using namespace std;
bool port_is_open(const string& address, int port) {
sf::TcpSocket socket;
bool open = (socket.connect(sf::IpAddress(address), port) == sf::Socket::Done);
socket.disconnect();
return open;
}
int main() {
cout << "Enter IP number: ";
string address;
cin >> address;
cout << "Enter Port number: ";
int port;
cin >> port;
if (port_is_open(address, port)) {
cout << "Port " << port << ": OPEN" << endl;
}
else {
cout << "Port " << port << ": CLOSED" << endl;
}
return 0;
}
But I wouldn't be here if this was working.
Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "public: virtual __thiscall sf::Socket::~Socket(void)" (??1Socket@sf@@UAE@XZ) referenced in function "public: virtual __thiscall sf::TcpSocket::~TcpSocket(void)" (??1TcpSocket@sf@@UAE@XZ) PortScannerWin32 c:\Users\James\documents\visual studio 2017\Projects\PortScannerWin32\PortScannerWin32\PortScanner.obj 1
Error LNK2019 unresolved external symbol "public: __thiscall sf::TcpSocket::TcpSocket(void)" (??0TcpSocket@sf@@QAE@XZ) referenced in function "bool __cdecl port_is_open(class std::basic_string,class std::allocator > const &,int)" (?port_is_open@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) PortScannerWin32 c:\Users\James\documents\visual studio 2017\Projects\PortScannerWin32\PortScannerWin32\PortScanner.obj 1
Error LNK2019 unresolved external symbol "public: enum sf::Socket::Status __thiscall sf::TcpSocket::connect(class sf::IpAddress const &,unsigned short,class sf::Time)" (?connect@TcpSocket@sf@@QAE?AW4Status@Socket@2@ABVIpAddress@2@GVTime@2@@Z) referenced in function "bool __cdecl port_is_open(class std::basic_string,class std::allocator > const &,int)" (?port_is_open@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) PortScannerWin32 c:\Users\James\documents\visual studio 2017\Projects\PortScannerWin32\PortScannerWin32\PortScanner.obj 1
Error LNK2019 unresolved external symbol "public: void __thiscall sf::TcpSocket::disconnect(void)" (?disconnect@TcpSocket@sf@@QAEXXZ) referenced in function "bool __cdecl port_is_open(class std::basic_string,class std::allocator > const &,int)" (?port_is_open@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) PortScannerWin32 c:\Users\James\documents\visual studio 2017\Projects\PortScannerWin32\PortScannerWin32\PortScanner.obj 1
Error LNK2019 unresolved external symbol "public: __thiscall sf::IpAddress::IpAddress(class std::basic_string,class std::allocator > const &)" (??0IpAddress@sf@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "bool __cdecl port_is_open(class std::basic_string,class std::allocator > const &,int)" (?port_is_open@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) PortScannerWin32 c:\Users\James\documents\visual studio 2017\Projects\PortScannerWin32\PortScannerWin32\PortScanner.obj 1
Error LNK2001 unresolved external symbol "public: static class sf::Time const sf::Time::Zero" (?Zero@Time@sf@@2V12@B) PortScannerWin32 c:\Users\James\documents\visual studio 2017\Projects\PortScannerWin32\PortScannerWin32\PortScanner.obj 1
Warning LNK4272 library machine type 'x64' conflicts with target machine type 'X86' PortScannerWin32 D:\SFML-2.4.2\lib\sfml-network-d.lib 1Error LNK1120 6 unresolved externals PortScannerWin32 c:\users\james\documents\visual studio 2017\Projects\PortScannerWin32\Debug\PortScannerWin32.exe 1
Those are my errors and if I am honest, I literally have no clue at all. I have followed the tutorials word by word and typed in the dependencies etc.
Anyone have any idea what is going wrong? I would say the obvious answer is 2015 being used in VS 2017 but a lot of forums have said that it works with no problems as there was an update in the SFML 2015 that allowed this.