I'm starting a simple program that uses Winsock and after I set up the simple functions VC++2010 throws Linker errors.
1>------ Build started: Project: Barbados++, Configuration: Debug Win32 ------1> server.cpp 1> Generating Code... 1> Skipping... (no relevant changes detected) 1> client.cpp 1>server.obj : error LNK2005: "int __cdecl init(void)" (?init@@YAHXZ) already defined in client.obj 1>server.obj : error LNK2005: _main already defined in client.obj 1>client.obj : error LNK2019: unresolved external symbol __imp__WSACleanup@0 referenced in function _main 1>server.obj : error LNK2001: unresolved external symbol __imp__WSACleanup@0 1>client.obj : error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function _main 1>server.obj : error LNK2001: unresolved external symbol __imp__WSAStartup@8 1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I think that after the @ is the address (from some MSDN documentation I read a while ago).
This is the code:
client.cpp:
//client.cpp
#include "api.h"
int main(void)
{
const int iReqWinsockVer = 2; // Minimum winsock version required
WSADATA wsaData;
if(WSAStartup(MAKEWORD(iReqWinsockVer,0), &wsaData)==0)
{
// Check if major version is at least iReqWinsockVer
if(LOBYTE(wsaData.wVersion) >= iReqWinsockVer)
{
/* ------- Call winsock functions here ------- */
}
else
{
// Required version not available
}
// Cleanup winsock
if(WSACleanup() != 0)
{
// cleanup failed
}
}
else
{
// startup failed
}
}
server.cpp:
//server.cpp
#include "api.h"
int main(void)
{
const int iReqWinsockVer = 2; // Minimum winsock version required
WSADATA wsaData;
if(WSAStartup(MAKEWORD(iReqWinsockVer,0), &wsaData)==0)
{
// Check if major version is at least iReqWinsockVer
if(LOBYTE(wsaData.wVersion) >= iReqWinsockVer)
{
/* ------- Call winsock functions here ------- */
}
else
{
// Required version not available
}
// Cleanup winsock
if(WSACleanup() != 0)
{
// cleanup failed
}
}
else
{
// startup failed
}
}
api.h:
//api.h
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <WinSock2.h>
#include <Windows.h>
using namespace std;
int init(void)
{
//Startup processes and such...
return 0;
}
Probably me with my lack of experience with such Linker errors, but any help would be great.
Thanks,


Sign In
Create Account


Back to top









