LNK2001
-
Hi, also ich habe hier einen kleinen Code:
#include <iostream> #include <string> #include <winsock2.h> #include <windows.h> using namespace std; void InitPop(); void ClosePop(); void GetMessage(); void SendCommand(string); // Fixed Strings string ProgName="POP_IT\t - Version 2.0"; string Frame="--------------------------------------------"; // Network Variables int MeinSocket; // Socket #define PORT 110 #define IP_GMX "213.165.64.20" //pop.gmx.net // Send Textstring char TextString[1024]; string command; string key; int bytes; int main() { // Willkommen cout<<"\n"; cout<<Frame<<"\n"; cout<<ProgName<<"\n"; cout<<Frame<<"\n\n"; // Init Socket TCP/IP Connection to POP Server InitPop(); // GREETING STATE // Look for Message GetMessage(); // AUTHORIZATION STATE cout<<"[?] Username: "; cin>>key; // Send Username command = "USER "+ key + " \n"; SendCommand(command); // Look for Message GetMessage(); // Send Password cout<<"[?] Password: "; cin>>key; command = "PASS "+ key + " \n"; SendCommand(command); // Look for Message GetMessage(); // TRANSACTION STATE // Send STAT / RETR command = "RETR 3\n"; SendCommand(command); // Look for Message GetMessage(); // QUIT - UPDATE STATE // Send QUIT command = "QUIT \n"; SendCommand(command); // Look for Message GetMessage(); cout<<"[!] Enter [q]\n"; cin>>key; // End Connection ClosePop(); return 0; } // Get Message from Mailserver void GetMessage() { // Clear Buffer memset(&TextString, '\0', sizeof(TextString)); // Receive String bytes = recv(MeinSocket, TextString, sizeof(TextString),0); if (bytes == -1) { // Data Error - recv() failed cout<<"[ERROR] - Recv() failed\n"; } else { // Success // Clear last byte TextString[bytes]='\0'; // Print Text cout<<"[:] "<<TextString<<""; } } // Send Command to mailserver void SendCommand(string com) { // Clear Buffer memset(&TextString, '\0', sizeof(TextString)); strncpy(TextString,com.c_str(),com.size()); bytes = send(MeinSocket, TextString, strlen(TextString), 0); if (bytes == -1) { // Fehler - send() failed cout<<"[ERROR] - Send() failed: "<<TextString<<"\n"; } else { // Success cout<<"[!] Command: "<<TextString<<""; } } // Init the POP Session void InitPop() { // Windows Sockets initialisieren #ifdef _WIN32 WSADATA wsa; if (WSAStartup(MAKEWORD(1, 1), &wsa)) { // Fehler - WSAStartup() failed cout<<"[ERROR] - WSA Startup failed\n"; } #endif // Socket erstellen MeinSocket = socket(AF_INET, SOCK_STREAM,0); if (MeinSocket == -1) { // Fehler - socket() failed cout<<"[ERROR] - Socket() failed\n"; } // Mit Server verbinden struct sockaddr_in ServerAddr; ServerAddr.sin_addr.s_addr = inet_addr(IP_GMX); // IP ServerAddr.sin_family = AF_INET; // Bereich ServerAddr.sin_port = htons(PORT); // Port if (connect(MeinSocket,(struct sockaddr*) &ServerAddr,sizeof(ServerAddr))== -1) { // Fehler - connect() failed cout<<"[ERROR] - Listen() failed\n"; } else { // Connected to server cout<<"[!] Connected to server: POP.GMX.NET\n"; } } // Close the POP Session void ClosePop() { // Close Connection #ifdef _WIN32 closesocket(MeinSocket); WSACleanup(); #else close(MeinSocket); #endif cout<<"[!] Connection Closed\n"; } /* End of File */
Soweit so gut. Wenn ich es aber kompiliere, bekomme ich folgende Fehler:
lol.obj : error LNK2001: Nichtaufgeloestes externes Symbol __imp__recv@16 lol.obj : error LNK2001: Nichtaufgeloestes externes Symbol __imp__send@16 lol.obj : error LNK2001: Nichtaufgeloestes externes Symbol __imp__connect@12 lol.obj : error LNK2001: Nichtaufgeloestes externes Symbol __imp__htons@4 lol.obj : error LNK2001: Nichtaufgeloestes externes Symbol __imp__inet_addr@4 lol.obj : error LNK2001: Nichtaufgeloestes externes Symbol __imp__socket@12 lol.obj : error LNK2001: Nichtaufgeloestes externes Symbol __imp__WSAStartup@8 lol.obj : error LNK2001: Nichtaufgeloestes externes Symbol __imp__WSACleanup@0 lol.obj : error LNK2001: Nichtaufgeloestes externes Symbol __imp__closesocket@4 Debug/lol.exe : fatal error LNK1120: 9 unaufgeloeste externe Verweise Fehler beim Ausführen von link.exe. lol.exe - 10 Fehler, 0 Warnung(en)
Meine Projektoptionen sind:
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/lol.pdb" /debug /machine:I386 /out:"Debug/lol.exe" /pdbtype:sept
und ich benutze Microsoft Visual C++ 6.0
Wie bekomm ich die Fehler weg? Währe nett, wenn jemand einen Einfall hätte, danke schonmal
-
Du musst die WinSock-Library mitbinden, in den Linkeroptionen unter Input-Libraries die winsock32.lib (oder ähnlicher Name, siehe MSDN) mitlinken.
MfG SideWinder
-
Jippieh danke, das wars...
MSDN sagt wsock32.lib nicht winsock32.libVielen Dank!