0

我正在 Microsoft Visual Studio Express 2012,C++ 中制作一个程序,以使用此 mac 地址与设备建立简单的蓝牙连接:“00:12:08:24:15:50”,

#include "stdafx.h"
#include <WinSock2.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <bluetoothapis.h>
#include <ws2bth.h>

typedef ULONGLONG bt_addr, *pbt_addr, BT_ADDR, *PBT_ADDR;

int main()
{
    WSADATA wsd;
    SOCKET client_socket; 
    SOCKADDR_BTH sa;
    BT_ADDR b;

    b = 0x001208241550;

    WSAStartup (MAKEWORD(1,0), &wsd);

    client_socket = socket (AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);

    memset (&sa, 0, sizeof(sa));
    sa.btAddr = b;
    sa.port = 1;

    if (connect (client_socket, (SOCKADDR *)&sa, sizeof(sa))){  
        //Perform error handling.
        closesocket (client_socket);
        return 0;
    }

    closesocket(client_socket);
    CloseHandle ((LPVOID)client_socket);
    WSACleanup();

    return 0;
}

当我构建它时,它总是给我以下错误:

error LNK2019: unresolved external symbol __imp__closesocket@4 referenced in function _main C:\Users\Strawhatphil\Documents\Visual Studio 2012\Projects\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.obj ConsoleApplication8
error LNK2019: unresolved external symbol __imp__connect@12 referenced in function _main    C:\Users\Strawhatphil\Documents\Visual Studio 2012\Projects\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.obj ConsoleApplication8
error LNK2019: unresolved external symbol __imp__socket@12 referenced in function _main C:\Users\Strawhatphil\Documents\Visual Studio 2012\Projects\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.obj ConsoleApplication8
error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function _main  C:\Users\Strawhatphil\Documents\Visual Studio 2012\Projects\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.obj ConsoleApplication8
error LNK2019: unresolved external symbol __imp__WSACleanup@0 referenced in function _main  C:\Users\Strawhatphil\Documents\Visual Studio 2012\Projects\ConsoleApplication8\ConsoleApplication8\ConsoleApplication8.obj ConsoleApplication8
error LNK1120: 5 unresolved externals   C:\Users\Strawhatphil\Documents\Visual Studio 2012\Projects\ConsoleApplication8\Debug\ConsoleApplication8.exe   ConsoleApplication8

我做错了什么我该如何解决这个问题?

4

3 回答 3

1

想想,你必须添加Ws2_32.lib到链接库列表中。

于 2013-05-29T16:23:54.353 回答
0

您需要安装 Windows Platform SDK,它会安装很多库。在安装位置的 lib 目录中将是文件 ws2_32.lib,它是您要链接的 Winsock2 库。

于 2013-05-30T07:54:01.517 回答
0

您必须转到项目的属性然后配置属性,在链接器选项中转到条目并选择附加依赖项并进行编辑。添加 ws2_32.lib 和 bthprops.lib 库。顺便说一句,我有带有 sdk 和 Visual Studio 2013 的 Windows 7

于 2015-02-04T00:51:47.983 回答