000
27.11.2004, 04:52 Uhr
Joltan
|
Hallo, da ich gerade etwas mit Socketsprogrammierung herumexperimentiere wollte ich mir ein Beispielprogramm compilieren, welches ich im Netz gefunden hatte (link siehe Header unten). Leider steigt der Linker jedesmal mit folgender Fehlermeldung aus:
Code: |
Compiling... main.cpp Linking... main.obj : error LNK2019: unresolved external symbol __imp__WSACleanup@0 referenced in function _main main.obj : error LNK2019: unresolved external symbol __imp__closesocket@4 referenced in function _main main.obj : error LNK2019: unresolved external symbol __imp__recv@16 referenced in function _main main.obj : error LNK2019: unresolved external symbol __imp__send@16 referenced in function _main main.obj : error LNK2019: unresolved external symbol __imp__connect@12 referenced in function _main main.obj : error LNK2019: unresolved external symbol __imp__inet_addr@4 referenced in function _main main.obj : error LNK2019: unresolved external symbol __imp__htons@4 referenced in function _main main.obj : error LNK2019: unresolved external symbol __imp__socket@12 referenced in function _main main.obj : error LNK2019: unresolved external symbol __imp__WSAGetLastError@0 referenced in function _main main.obj : error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function "long __cdecl WinsockStartup(void)" (?WinsockStartup@@YAJXZ) Debug/whois.exe : fatal error LNK1120: 10 unresolved externals
|
Ich verwende die VC++ 2005 Express Beta und habe das Platform SDK korrekt installiert soweit ich das sehe. Pfade stimmen auch...
Irgendwelche Vorschläge wo ich noch drehen/schrauben könnte?
Hier der Quellcode:
C++: |
// whois.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
/************************************************************ Whois Client für ch Domains Programmed by c-worker www.c-worker.ch
*************************************************************/
#include <iostream> #include <windows.h> #include <winsock2.h> #include <time.h>
using namespace std;
// whois.nic.ch #define WHOIS_SERVER_IP "130.59.1.81" #define WHOIS_PORT 43
// Prototypen long WinsockStartup(); unsigned long WINAPI RecvData(void *s);
int _tmain(int argc, _TCHAR* argv[]) { long rc; SOCKET whoisSocket; SOCKADDR_IN whoisAddr;
char recvBuf[10000]; char sendBuf[256];
int sendSize=0;
cout << "Domain Name: " << endl; cin >> sendBuf;
for(sendSize=0;sendSize<256;sendSize++) { if(sendBuf[sendSize] == '\0') { sendBuf[sendSize] = '\n'; sendBuf[sendSize+1] = '\0'; sendSize +=1; break; } }
rc = WinsockStartup(); if (rc == SOCKET_ERROR) { cout << "WSAStartup Error " << WSAGetLastError() << endl; return rc; }
whoisSocket = socket(AF_INET, SOCK_STREAM,NULL); if (whoisSocket == INVALID_SOCKET) { cout << "Invalid Socket Error " << WSAGetLastError() << endl; return rc; }
whoisAddr.sin_family = AF_INET; whoisAddr.sin_port = htons(WHOIS_PORT); whoisAddr.sin_addr.s_addr = inet_addr(WHOIS_SERVER_IP); if (whoisAddr.sin_addr.s_addr == INADDR_NONE) { cout << "Invalid IP Error !" << endl; return SOCKET_ERROR; }
cout << "Connecting ...\n\n" << endl; rc = connect(whoisSocket, (SOCKADDR*) &whoisAddr, sizeof(whoisAddr)); if (rc == SOCKET_ERROR) { cout << "Cannot connect to whois Server, Error: " << WSAGetLastError() << endl; return rc; }
rc = send (whoisSocket, &sendBuf[0], sendSize , NULL); if(rc == SOCKET_ERROR) { cout << "Cannot send Data to whois Server, Error: " << WSAGetLastError() << endl; return rc; }
rc = recv (whoisSocket, &recvBuf[0], sizeof(recvBuf), NULL); cout << "\n" << recvBuf << endl;
rc = closesocket(whoisSocket); WSACleanup();
return 0; }
long WinsockStartup() { long rc;
WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD( 2, 2 );
rc = WSAStartup( wVersionRequested, &wsaData ); return rc; }
|
stdafx.h:
C++: |
// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently //
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include <stdio.h> #include <tchar.h>
// TODO: reference additional headers your program requires here
|
Dieser Post wurde am 27.11.2004 um 04:53 Uhr von Joltan editiert. |