2017-06-08 42 views
0

所以我想寫一些網絡相關的代碼,特別是使用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中有一個更新允許這樣做。

+0

聽起來像你還沒有鏈接圖書館。 – Sneftel

+0

在Linker-> General中,我填寫了D:\ SFML-2.4.2 \ lib附加庫目錄,是不是鏈接?我輸入了依賴關係,還有什麼我必須做的嗎? – toiletduck123

+0

[什麼是未定義的引用/無法解析的外部符號錯誤,以及如何解決它?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-符號錯誤和如何-DO-修復) – Sneftel

回答

2

我沒有這個庫的任何知識,但這些看起來像很標準的鏈接器錯誤。連接VS 2017(平臺工具集v141)與使用VS 2015編譯的庫(Plaform Toolset v141)應該沒有問題。微軟已經在VS 2015和2017的編譯器之間保持了二進制兼容性,這允許在相同的可執行文件中混合編譯的代碼。

您正在使用的頭文件包含(SFML/Network.hpp)「promise」實現。鏈接器的工作是將「承諾」與實際實現(包含在靜態庫(.lib)中)進行匹配,並將它們放在一起以創建您的exe。

注意最後的警告:

Warning LNK4272 library machine type 'x64' conflicts with target machine type 'X86' PortScannerWin32 D:\SFML-2.4.2\lib\sfml-network-d.lib 1 

作爲第一步,我會改變的Visual Studio,以64中的項目平臺的價值,所以圖書館的「位數」匹配您的executible的。這是本地機器代碼,因此生成的代碼必須適用於相同的體系結構。

請注意,在更改此設置時,可能需要設置項目屬性(如include和庫路徑以及鏈接器輸入),以便編譯代碼。您可以使用項目屬性表將x64值設置爲x86平臺中的值。

3

您沒有鏈接到正確的圖書館平臺。

警告LNK4272庫機器類型 '64' 與目標機器類型 'X86' PortScannerWin32 d衝突:\ SFML-2.4.2 \ lib中\ SFML網絡-d.lib 1

此狀態當你的項目在32位時,你正在連接一個64位庫。確保採取正確的庫,或者更新您的項目以將其構建爲64位項目。