0

I'm making a program in Microsoft visual studio express 2012, C++, to make a simple bluetooth connection to a device with this mac addres:"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;
}

and when I build it, it allways gives me the following errors:

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

what am I doing wrong how do I fix this?

mwerschy
  • 1,698
  • 1
  • 15
  • 26
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?: Failure to link against appropriate libraries/object files or compile implementation files](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Raymond Chen May 29 '13 at 19:48

3 Answers3

1

Think, you must add Ws2_32.lib to list of linked libraries.

loentar
  • 5,111
  • 1
  • 24
  • 25
  • 1
    Sounds like a poster that IBM used to hang on the office walls, it said "Think!". They had to take them down when employees added "or thwim!" – Hans Passant May 29 '13 at 17:14
0

You need to install the Windows Platform SDK, which will install a lot of libraries. In the install location's lib directory will be the file ws2_32.lib, which is the Winsock2 library you want to link against.

Santosh Dhanawade
  • 1,756
  • 14
  • 29
0

you have to go to the properties of your project then configuration properties, in the linker options go to the entry and select aditional dependencies and edit it. Add the ws2_32.lib and bthprops.lib libraries. By the way i have windows 7 with the sdk and visual studio 2013