所以我想寫一些網絡相關的代碼,特別是使用SFML的端口掃描器。我運行VS 2017年和已經下載了SFML建立然而2015年人說這應該與2017年用於Visual C++ 2017的SFML 2.4.2使用SFML的2015版本
我的演示代碼工作至今試試,看看圖書館工作是:
#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;
}
但如果這個工作正常,我不會在這裏。
嚴重性代碼說明項目文件的線路抑制狀態 錯誤LNK2019解析的外部符號 「市民:虛擬__thiscall SF ::插座::〜插槽(無效)」(?? 1Socket @ SF @@ UAE @ XZ)引用在函數「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
錯誤LNK2019未解析的外部符號「public:__thiscall sf :: TcpSocket :: TcpSocket(void)」(?? 0TcpSocket @ sf @@ QAE @ XZ)在函數「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年\項目\ PortScannerWin32 \ PortScannerWin32 \ PortScanner.obj 1
錯誤LNK2019解析的外部符號「公用:枚舉SF ::插座::狀態__thiscall SF :: ::的TCPSocket連接(類SF :: Ip地址常量(函數「bool __cdecl port_is_open(class std)」中引用的「(?connect @ TcpSocket @ sf @@ QAE?AW4Status @ Socket @ 2 @ ABVIpAddress @ 2 @ GVTime @ 2 @@ Z) :: 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
錯誤LNK2019未解析的外部符號「public:void __thiscall sf :: TcpSocket :: disconnect(void)」(?disconnect @TcpSocket @ sf @@ QAEXXZ)在函數「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
錯誤LNK2019無法解析的外部符號「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 )在函數「bool __cd」中引用ecl 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
錯誤LNK2001無法解析的外部符號「public:static class sf :: Time PortscannerWin32 c:\ Users \ James \ documents \ visual studio 2017 \ Projects \ PortScannerWin32 \ PortScannerWin32 \ PortScanner.obj 1
警告LNK4272「const sf :: Time :: Zero」(?Zero @ Time @ sf @@ 2V12 @ B)庫機器類型'x64'與目標機器類型'X86'衝突PortScannerWin32 D:\ SFML-2.4.2 \ lib \ sfml-network-d.lib 1錯誤LNK1120 6個未解析的外部PortScannerWin32 c:\ users \ james \ documents \ visual studio 2017 \ Projects \ PortScannerWin32 \ Debug \ PortScannerWin32。exe 1
這些是我的錯誤,如果我誠實,我幾乎沒有任何線索。我一直按照教程一字一句地輸入依賴關係等。
任何人有任何想法是什麼問題?我想說明顯的答案是2015年在VS 2017中使用,但很多論壇都表示,它在沒有問題的情況下工作,因爲SFML 2015中有一個更新允許這樣做。
聽起來像你還沒有鏈接圖書館。 – Sneftel
在Linker-> General中,我填寫了D:\ SFML-2.4.2 \ lib附加庫目錄,是不是鏈接?我輸入了依賴關係,還有什麼我必須做的嗎? – toiletduck123
[什麼是未定義的引用/無法解析的外部符號錯誤,以及如何解決它?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-符號錯誤和如何-DO-修復) – Sneftel