//error//
error lnk2019 unresolved external symbol
//code//
main.cpp-
#include <iostream>
#include <Windows.h>
#include <string>
#include <conio.h>
#include <MMSystem.h>
#include <winsock.h>
#include "Server.h"
#include "common.h"
#include "World.h"
#include "hero.h"
#include "Function.h"
using namespace std;
void main(){
int a;
cout << "You have woken up in a strange place you must escape... lets look around" << endl;
bool hero_win = false;
server();
// Create map //
world dungeon;
world tdungeon;
worldinit(dungeon);
//Fighting variables//
int havelost;
//define characters//
hero simon;
simon.name = "Simon";
simon.keys = 0;
simon.health = 100;
simon.damage = 10;
simon.x = 11;
simon.y = 9;
enemy goblin;
enemy badguy;
goblin.health = 100;
goblin.damage = 4;
goblin.x = 4;
goblin.y = 4;
char key = 0;
while (key != 'q'){
drawworld(dungeon, simon, 20, 40);
cout.clear();
//move the player, controls ect.
cout << "x:" << simon.x << "; y:" << simon.y << endl;
cout << "Keys:" << simon.keys << endl;
cout << "health:" << simon.health << endl;
cout << "damage:" << simon.damage << endl;
cout << "Move (a/w/s/d):" << endl;
key = _getch();
int dx = 0, dy = 0;
switch (key)
{
case 's':
dy = 1;
break;
case 'w':
dy = -1;
break;
case 'a':
dx = -1;
break;
case 'd':
dx = 1;
break;
default:
continue;
}
if (dx != 0 || dy != 0) {
heromove(dungeon, simon, goblin, dx, dy);
}
if (dungeon.map[simon.y][simon.x] == 3){
cout << "YOU WIN" << endl;
system("pause");
simon.x = 11;
simon.y = 10;
worldinit(dungeon);
}
}
}
void opendoor(hero& _hero, world& _world, int ny, int nx){
if (_hero.keys == 1 || _hero.keys > 1){
_world.map[nx][ny] = 0;
}
}
server.h-
#ifndef SIMON_SERVER_H
#define SIMON_SERVER_H
int server();
#endif
server.cpp-
#include <winsock.h>
#include "common.h"
#include "Function.h"
#include "Hero.h"
#include "World.h"
using namespace std;
int server(){
WSAData wsa;
WORD Version = MAKEWORD(2, 1);
WSAStartup(Version, &wsa);
SOCKET Listeen = socket(AF_INET, SOCK_STREAM, NULL);
SOCKET Connect = socket(AF_INET, SOCK_STREAM, NULL);
SOCKADDR_IN Server;
Server.sin_addr.s_addr = inet_addr("192.168.0.1");
Server.sin_family = AF_INET;
Server.sin_port = htons(100);
bind(Listeen, (SOCKADDR*)&Server, sizeof(Server));
listen(Listeen, 1);
int size = sizeof(Server);
cout << "Listening" << endl;
for (;;)
{
if (Connect = accept(Listeen, (SOCKADDR*)&Server, &size)){
cout << "Connection was reached" << endl;
break;
}
}
WSACleanup();
cin.get();
return 0;
}
//More error info//
Error 4 error LNK2019: unresolved external symbol _accept@12 referenced in function "int __cdecl server(void)" (?server@@YAHXZ) C:\Users\Ifyournotsimonleave\Desktop\C++\simonworld\Sample\Server.obj Sample
Error 5 error LNK2019: unresolved external symbol _bind@12 referenced in function "int __cdecl server(void)" (?server@@YAHXZ) C:\Users\Ifyournotsimonleave\Desktop\C++\simonworld\Sample\Server.obj Sample
Error 6 error LNK2019: unresolved external symbol _htons@4 referenced in function "int __cdecl server(void)" (?server@@YAHXZ) C:\Users\Ifyournotsimonleave\Desktop\C++\simonworld\Sample\Server.obj Sample
Error 7 error LNK2019: unresolved external symbol _inet_addr@4 referenced in function "int __cdecl server(void)" (?server@@YAHXZ) C:\Users\Ifyournotsimonleave\Desktop\C++\simonworld\Sample\Server.obj Sample
Error 8 error LNK2019: unresolved external symbol _listen@8 referenced in function "int __cdecl server(void)" (?server@@YAHXZ) C:\Users\Ifyournotsimonleave\Desktop\C++\simonworld\Sample\Server.obj Sample
Error 9 error LNK2019: unresolved external symbol _socket@12 referenced in function "int __cdecl server(void)" (?server@@YAHXZ) C:\Users\Ifyournotsimonleave\Desktop\C++\simonworld\Sample\Server.obj Sample
Error 10 error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function "int __cdecl server(void)" (?server@@YAHXZ) C:\Users\Ifyournotsimonleave\Desktop\C++\simonworld\Sample\Server.obj Sample
Error 11 error LNK2019: unresolved external symbol _WSACleanup@0 referenced in function "int __cdecl server(void)" (?server@@YAHXZ) C:\Users\Ifyournotsimonleave\Desktop\C++\simonworld\Sample\Server.obj Sample
Error 12 error LNK1120: 8 unresolved externals C:\Users\Ifyournotsimonleave\Desktop\C++\simonworld\Debug\Sample.exe 1 1 Sample
As explained in the winsocks documentation, you have to link in Ws2_32.lib
You need to link the actual socket library (not enough to just include the winsock.h): ws2_32.lib
Add this in your code (top of file):
#pragma comment(lib,"Ws2_32.lib")
or
Open the Project properties, go to Linker -> Input, and the add the ws2_32.lib to Additional Dependencies edit line.