简体   繁体   English

使用SFML 2015版本的Visual C ++ 2017 SFML 2.4.2

[英]SFML 2.4.2 for Visual C++ 2017 using the 2015 build of SFML

So I am trying to write some network related code, specifically a port scanner using SFML. 因此,我尝试编写一些与网络相关的代码,特别是使用SFML的端口扫描程序。 I am running VS 2017 and have downloaded the SFML build for 2015 however people have said this should work with 2017. 我正在运行VS 2017并下载了2015年的SFML版本,但是人们说这应该适用于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 严重性代码说明项目文件行抑制状态错误LNK2019无法解析的外部符号“ public:virtual __thiscall sf :: Socket ::〜Socket(void)”(?? 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

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 错误LNK2019无法解析的外部符号“ public:__thiscall sf :: TcpSocket :: TcpSocket(void)”(?? 0TcpSocket @ sf @@ QAE @ XZ)在函数“ bool __cdecl port_is_open(class std :: basic_string,class std :::”中引用)分配器> 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 错误LNK2019无法解析的外部符号“ public:枚举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)在函数“ 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 错误LNK2019无法解析的外部符号“ public:void __thiscall sf :: TcpSocket :: disconnect(void)”(?disconnect @ TcpSocket @ sf @@ QAEXXZ)在函数“ bool __cdecl port_is_open(class std :: basic_string,class std :::”中引用)分配器> 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 错误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 __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 错误LNK2001无法解析的外部符号“ public:静态类sf :: Time const sf :: Time :: Zero”(?Zero @ Time @ sf @@ 2V12 @ B)PortScannerWin32 c:\\ Users \\ James \\ documents \\ visual studio 2017 \\项目\\ 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 1 警告LNK4272库计算机类型'x64'与目标计算机类型'X86'冲突PortScannerWin32 D:\\ SFML-2.4.2 \\ lib \\ sfml-network-d.lib 1

Error LNK1120 6 unresolved externals PortScannerWin32 c:\\users\\james\\documents\\visual studio 2017\\Projects\\PortScannerWin32\\Debug\\PortScannerWin32.exe 1 错误LNK1120 6无法解析的外部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. 我想说的很明显的答案是2015年在VS 2017中使用,但很多论坛都说它可以正常工作,因为SFML 2015中有一个更新允许这样做。

You are not linking against the correct library platform. 您没有链接到正确的库平台。

Warning LNK4272 library machine type 'x64' conflicts with target machine type 'X86' PortScannerWin32 D:\\SFML-2.4.2\\lib\\sfml-network-d.lib 1 警告LNK4272库计算机类型'x64'与目标计算机类型'X86'冲突PortScannerWin32 D:\\ SFML-2.4.2 \\ lib \\ sfml-network-d.lib 1

This states that you are linking against a 64bits library while your project is in 32bits. 这表明您在32位项目中链接到64位库。 Make sure to take the correct library, or update your project to build it as a 64bits project. 确保采用正确的库,或更新您的项目以将其构建为64位项目。

I don't have any knowledge of this library, but these seem like pretty standard linker errors. 我对该库没有任何了解,但是这些似乎是非常标准的链接器错误。 There should be no problem linking VS 2017 (Platform Toolset v141) with libraries compiled with VS 2015 (Plaform Toolset v141). 将VS 2017(Platform Toolset v141)与用VS 2015(Plaform Toolset v141)编译的库链接在一起应该没有问题。 Microsoft have kept binary compatibility between the compilers in VS 2015 and 2017, which allows mixing code compiled with either together in the same executible. 微软在VS 2015和2017中保持了编译器之间的二进制兼容性,从而允许将在同一可执行文件中一起编译的代码混合在一起。

The header file your are including ( SFML/Network.hpp ) "promises" implementations for the classes you are using. 您正在使用的头文件包括( SFML/Network.hpp )“ promises”实现。 It's the linker's job to match up the "promises" with the actual implementations, contained in a static lib (.lib), and put them together to create your exe. 链接程序的工作是将“承诺”与包含在静态lib(.lib)中的实际实现进行匹配,并将它们放在一起以创建您的exe。

Note the last warning: 注意最后的警告:

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

As a first step, I would change the platform value on your project within Visual Studio to x64, so the "bitness" of the library matches that of your executible. 第一步,我将Visual Studio中项目的平台值更改为x64,以便库的“位数”与可执行文件的“位数”匹配。 This is native machine code, so the generated code must be for the same architecture. 这是本机代码,因此生成的代码必须用于相同的体系结构。

Note that when changing this, you might need to set project properties such as the include and library paths, as well as linker inputs, so that your code compiles. 请注意,更改此设置时,可能需要设置项目属性,例如include和library路径以及链接器输入,以便编译代码。 You can use the project property sheets to set the x64 values to those in the x86 platform. 您可以使用项目属性表将x64值设置为x86平台中的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM