c语言 未解决的外部符号'startup_value_1',c++ 未解决的外部符号LNK2019

首先,我知道这个问题是在这个网站上,但是我已经看了几乎所有的这些,似乎找不到什么问题。这是在VS 2012谢谢。

//Socket.h

#pragma once

#include

#include

using namespace std;

const int STRLEN = 256;

class Socket

{

protected:

WSADATA wsaData;

SOCKET mySocket;

SOCKET myBackup;

SOCKET acceptSocket;

sockaddr_in myAddress;

public:

Socket();

~Socket();

bool SendData( char* );

bool RecvData( char*, int );

void CloseConnection();

void GetAndSendMessage();

};

class ServerSocket : public Socket

{

public:

void Listen();

void Bind( int port );

void StartHosting( int port );

};

class ClientSocket : public Socket

{

public:

void ConnectToServer( const char *ipAddress, int port );

};

这是Socket.cpp

//Socket.cpp

#include "stdafx.h"

#include "Socket.h"

Socket::Socket()

{

if( WSAStartup( MAKEWORD(2, 2), &wsaData ) != NO_ERROR )

{

cerr<

system("pause");

WSACleanup();

exit(10);

}

//Create a socket

mySocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );

if ( mySocket == INVALID_SOCKET )

{

cerr<

system("pause");

WSACleanup();

exit(11);

}

myBackup = mySocket;

}

Socket::~Socket()

{

WSACleanup();

}

bool Socket::SendData( char *buffer )

{

send( mySocket, buffer, strlen( buffer ), 0 );

return true;

}

bool Socket::RecvData( char *buffer, int size )

{

int i = recv( mySocket, buffer, size, 0 );

buffer[i] = '\0';

return true;

}

void Socket::CloseConnection()

{

//cout<

closesocket( mySocket );

mySocket = myBackup;

}

void Socket::GetAndSendMessage()

{

char message[STRLEN];

cin.ignore();//without this, it gets the return char from the last cin and ignores the following one!

cout< ";

cin.get( message, STRLEN );

SendData( message );

}

void ServerSocket::StartHosting( int port )

{

Bind( port );

Listen();

}

void ServerSocket::Listen()

{

//cout<

if ( listen ( mySocket, 1 ) == SOCKET_ERROR )

{

cerr<

system("pause");

WSACleanup();

exit(15);

}

//cout<

acceptSocket = accept( myBackup, NULL, NULL );

while ( acceptSocket == SOCKET_ERROR )

{

acceptSocket = accept( myBackup, NULL, NULL );

}

mySocket = acceptSocket;

}

void ServerSocket::Bind( int port )

{

myAddress.sin_family = AF_INET;

myAddress.sin_addr.s_addr = inet_addr( "0.0.0.0" );

myAddress.sin_port = htons( port );

//cout<

if ( bind ( mySocket, (SOCKADDR*) &myAddress, sizeof( myAddress) ) == SOCKET_ERROR )

{

cerr<

system("pause");

WSACleanup();

exit(14);

}

}

void ClientSocket::ConnectToServer( const char *ipAddress, int port )

{

myAddress.sin_family = AF_INET;

myAddress.sin_addr.s_addr = inet_addr( ipAddress );

myAddress.sin_port = htons( port );

//cout<

if ( connect( mySocket, (SOCKADDR*) &myAddress, sizeof( myAddress ) ) == SOCKET_ERROR )

{

cerr<

system("pause");

WSACleanup();

exit(13);

}

}

这里是stdafx.h

#pragma once

#include "targetver.h"

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers

// Windows Header Files:

#include

// C RunTime Header Files

#include

#include

#include

#include

// TODO: reference additional headers your program requires here

#include "Socket.h"

这里是我的错误信息:

1>------ Build started: Project: Client, Configuration: Debug Win32 ------

1> stdafx.cpp

1> Socket.cpp

1> Client.cpp

1> Generating Code...

1>Socket.obj : error LNK2019: unresolved external symbol __imp__accept@12 referenced in function "public: void __thiscall ServerSocket::Listen(void)" (?Listen@ServerSocket@@QAEXXZ)

1>Socket.obj : error LNK2019: unresolved external symbol __imp__bind@12 referenced in function "public: void __thiscall ServerSocket::Bind(int)" (?Bind@ServerSocket@@QAEXH@Z)

1>Socket.obj : error LNK2019: unresolved external symbol __imp__closesocket@4 referenced in function "public: void __thiscall Socket::CloseConnection(void)" (?CloseConnection@Socket@@QAEXXZ)

1>Socket.obj : error LNK2019: unresolved external symbol __imp__connect@12 referenced in function "public: void __thiscall ClientSocket::ConnectToServer(char const *,int)" (?ConnectToServer@ClientSocket@@QAEXPBDH@Z)

1>Socket.obj : error LNK2019: unresolved external symbol __imp__htons@4 referenced in function "public: void __thiscall ServerSocket::Bind(int)" (?Bind@ServerSocket@@QAEXH@Z)

1>Socket.obj : error LNK2019: unresolved external symbol __imp__inet_addr@4 referenced in function "public: void __thiscall ServerSocket::Bind(int)" (?Bind@ServerSocket@@QAEXH@Z)

1>Socket.obj : error LNK2019: unresolved external symbol __imp__listen@8 referenced in function "public: void __thiscall ServerSocket::Listen(void)" (?Listen@ServerSocket@@QAEXXZ)

1>Socket.obj : error LNK2019: unresolved external symbol __imp__recv@16 referenced in function "public: bool __thiscall Socket::RecvData(char *,int)" (?RecvData@Socket@@QAE_NPADH@Z)

1>Socket.obj : error LNK2019: unresolved external symbol __imp__send@16 referenced in function "public: bool __thiscall Socket::SendData(char *)" (?SendData@Socket@@QAE_NPAD@Z)

1>Socket.obj : error LNK2019: unresolved external symbol __imp__socket@12 referenced in function "public: __thiscall Socket::Socket(void)" (??0Socket@@QAE@XZ)

1>Socket.obj : error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function "public: __thiscall Socket::Socket(void)" (??0Socket@@QAE@XZ)

1>Socket.obj : error LNK2019: unresolved external symbol __imp__WSACleanup@0 referenced in function "public: __thiscall Socket::Socket(void)" (??0Socket@@QAE@XZ)

1>C:\Users\ajayp_000\documents\visual studio 2012\Projects\Client\Debug\Client.exe : fatal error LNK1120: 12 unresolved externals

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值