Ошибки компоновщика . подскажите что добавить
25.03.2013, 22:03. Показов 1114. Ответов 2
Есть такой код, работа с сокетами
Сыпет ошибками компоновщика
Подскажите в чем дело ?
| C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
| #include <string.h>
#include <winsock2.h>
#include <windows.h>
#include "conio.h"
#include "Ws2tcpip.h"
#pragma once
#define PORT 80
#pragma comment (lib, "user32.lib")
class http_client{
public:
http_client(){
struct addrinfo *ptr = NULL;
i=1;
ipbufferlength = 46;
buff = new char[10000];
}
~http_client(){
delete buff;
}
int get_ip(char* y){
WSAStartup(0x202, (WSADATA *)&buff[0]); //winsock2 init
return (getaddrinfo("www.mail.ru", NULL, NULL, &result));
}
int to_net_format(){
sockaddr_ipv4 = (struct sockaddr_in *) result->ai_addr;
servip= inet_ntoa(sockaddr_ipv4->sin_addr) ;
// Шаг 2 - создание сокета
my_sock = socket(AF_INET, SOCK_STREAM, 0);
// Шаг 3 - установка соединения
// заполнение структуры sockaddr_in - указание адреса и порта сервера
sockaddr_in dest_addr;
dest_addr.sin_family = AF_INET;
dest_addr.sin_port = htons(PORT);
HOSTENT *hst;
// преобразование IP адреса из символьного в сетевой формат
if (inet_addr(servip) != INADDR_NONE)
dest_addr.sin_addr.s_addr = inet_addr(servip);
else
{
// попытка получить IP адрес по доменному имени сервера
if (hst = gethostbyname(servip))
// hst->h_addr_list содержит не массив адресов,
// а массив указателей на адреса
((unsigned long *)&dest_addr.sin_addr)[0] = ((unsigned long **)hst->h_addr_list)[0][0];
else return -1;
}
}
int connection(){
return connect(my_sock, (sockaddr *)&dest_addr, sizeof(dest_addr));
}
int msg(){
send(my_sock, &buff[0], strlen(&buff[0]), 0);
recv (my_sock, &buff[0], strlen(&buff[0]), 0);
return(WSAGetLastError()) ;
}
char * all(char *domain){
error = (get_ip(domain)&&to_net_format()&&connection()&&msg());
return buff;
}
private:
struct addrinfo *result;
int error;
struct addrinfo *ptr;
int i;
struct sockaddr_in *sockaddr_ipv4;
DWORD ipbufferlength;
SOCKET my_sock;
sockaddr_in dest_addr;
char * buff;
char *servip;
};
char * and_SysStringToChar(System::String^ string)
{
return (char*)(void*)
System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi
(string);
}
/*System::String^ * and_CharToSysString(char* ch)
{
char * chr=new char[]=ch;
System::String^ str;
for(int i=0;chr[i]!='\0';i++)
{
str+=wchar_t(ch[i]);
}
return str;
}*/
namespace sipc {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Сводка для Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::TextBox^ textBox2;
protected:
private:
/// <summary>
/// Требуется переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->button2 = (gcnew System::Windows::Forms::Button());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(521, 24);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(119, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"GET";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(33, 27);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(382, 20);
this->textBox1->TabIndex = 1;
this->textBox1->Text = L"http://";
//
// button2
//
this->button2->Location = System::Drawing::Point(521, 85);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(119, 23);
this->button2->TabIndex = 2;
this->button2->Text = L"POST";
this->button2->UseVisualStyleBackColor = true;
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(33, 88);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(382, 20);
this->textBox2->TabIndex = 3;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(1093, 409);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->button2);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
http_client a;
char * t;
t = a.all( and_SysStringToChar(this->textBox1->Text));
this->textBox1->Text = gcnew String(reinterpret_cast<const char*>(t));
}
};
} |
|
| C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| 1>sipc.obj : error LNK2028: ссылка на неразрешенную лексему (0A00002F) "extern "C" int __stdcall WSAGetLastError(void)" (?WSAGetLastError@@$$J10YGHXZ) в функции "public: int __clrcall http_client::msg(void)" (?msg@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2028: ссылка на неразрешенную лексему (0A000030) "extern "C" int __stdcall recv(unsigned int,char *,int,int)" (?recv@@$$J216YGHIPADHH@Z) в функции "public: int __clrcall http_client::msg(void)" (?msg@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2028: ссылка на неразрешенную лексему (0A000032) "extern "C" int __stdcall send(unsigned int,char const *,int,int)" (?send@@$$J216YGHIPBDHH@Z) в функции "public: int __clrcall http_client::msg(void)" (?msg@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2028: ссылка на неразрешенную лексему (0A000033) "extern "C" int __stdcall connect(unsigned int,struct sockaddr const *,int)" (?connect@@$$J212YGHIPBUsockaddr@@H@Z) в функции "public: int __clrcall http_client::connection(void)" (?connection@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2028: ссылка на неразрешенную лексему (0A000034) "extern "C" struct hostent * __stdcall gethostbyname(char const *)" (?gethostbyname@@$$J14YGPAUhostent@@PBD@Z) в функции "public: int __clrcall http_client::to_net_format(void)" (?to_net_format@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2028: ссылка на неразрешенную лексему (0A000035) "extern "C" unsigned long __stdcall inet_addr(char const *)" (?inet_addr@@$$J14YGKPBD@Z) в функции "public: int __clrcall http_client::to_net_format(void)" (?to_net_format@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2028: ссылка на неразрешенную лексему (0A000036) "extern "C" unsigned short __stdcall htons(unsigned short)" (?htons@@$$J14YGGG@Z) в функции "public: int __clrcall http_client::to_net_format(void)" (?to_net_format@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2028: ссылка на неразрешенную лексему (0A000037) "extern "C" unsigned int __stdcall socket(int,int,int)" (?socket@@$$J212YGIHHH@Z) в функции "public: int __clrcall http_client::to_net_format(void)" (?to_net_format@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2028: ссылка на неразрешенную лексему (0A000038) "extern "C" char * __stdcall inet_ntoa(struct in_addr)" (?inet_ntoa@@$$J14YGPADUin_addr@@@Z) в функции "public: int __clrcall http_client::to_net_format(void)" (?to_net_format@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2028: ссылка на неразрешенную лексему (0A000039) "extern "C" int __stdcall getaddrinfo(char const *,char const *,struct addrinfo const *,struct addrinfo * *)" (?getaddrinfo@@$$J216YGHPBD0PBUaddrinfo@@PAPAU1@@Z) в функции "public: int __clrcall http_client::get_ip(char *)" (?get_ip@http_client@@$$FQAMHPAD@Z)
1>sipc.obj : error LNK2028: ссылка на неразрешенную лексему (0A00003A) "extern "C" int __stdcall WSAStartup(unsigned short,struct WSAData *)" (?WSAStartup@@$$J18YGHGPAUWSAData@@@Z) в функции "public: int __clrcall http_client::get_ip(char *)" (?get_ip@http_client@@$$FQAMHPAD@Z)
1>sipc.obj : error LNK2019: ссылка на неразрешенный внешний символ "extern "C" int __stdcall getaddrinfo(char const *,char const *,struct addrinfo const *,struct addrinfo * *)" (?getaddrinfo@@$$J216YGHPBD0PBUaddrinfo@@PAPAU1@@Z) в функции "public: int __clrcall http_client::get_ip(char *)" (?get_ip@http_client@@$$FQAMHPAD@Z)
1>sipc.obj : error LNK2019: ссылка на неразрешенный внешний символ "extern "C" int __stdcall WSAStartup(unsigned short,struct WSAData *)" (?WSAStartup@@$$J18YGHGPAUWSAData@@@Z) в функции "public: int __clrcall http_client::get_ip(char *)" (?get_ip@http_client@@$$FQAMHPAD@Z)
1>sipc.obj : error LNK2019: ссылка на неразрешенный внешний символ "extern "C" struct hostent * __stdcall gethostbyname(char const *)" (?gethostbyname@@$$J14YGPAUhostent@@PBD@Z) в функции "public: int __clrcall http_client::to_net_format(void)" (?to_net_format@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2019: ссылка на неразрешенный внешний символ "extern "C" unsigned long __stdcall inet_addr(char const *)" (?inet_addr@@$$J14YGKPBD@Z) в функции "public: int __clrcall http_client::to_net_format(void)" (?to_net_format@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2019: ссылка на неразрешенный внешний символ "extern "C" unsigned short __stdcall htons(unsigned short)" (?htons@@$$J14YGGG@Z) в функции "public: int __clrcall http_client::to_net_format(void)" (?to_net_format@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2019: ссылка на неразрешенный внешний символ "extern "C" unsigned int __stdcall socket(int,int,int)" (?socket@@$$J212YGIHHH@Z) в функции "public: int __clrcall http_client::to_net_format(void)" (?to_net_format@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2019: ссылка на неразрешенный внешний символ "extern "C" char * __stdcall inet_ntoa(struct in_addr)" (?inet_ntoa@@$$J14YGPADUin_addr@@@Z) в функции "public: int __clrcall http_client::to_net_format(void)" (?to_net_format@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2019: ссылка на неразрешенный внешний символ "extern "C" int __stdcall connect(unsigned int,struct sockaddr const *,int)" (?connect@@$$J212YGHIPBUsockaddr@@H@Z) в функции "public: int __clrcall http_client::connection(void)" (?connection@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2019: ссылка на неразрешенный внешний символ "extern "C" int __stdcall WSAGetLastError(void)" (?WSAGetLastError@@$$J10YGHXZ) в функции "public: int __clrcall http_client::msg(void)" (?msg@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2019: ссылка на неразрешенный внешний символ "extern "C" int __stdcall recv(unsigned int,char *,int,int)" (?recv@@$$J216YGHIPADHH@Z) в функции "public: int __clrcall http_client::msg(void)" (?msg@http_client@@$$FQAMHXZ)
1>sipc.obj : error LNK2019: ссылка на неразрешенный внешний символ "extern "C" int __stdcall send(unsigned int,char const *,int,int)" (?send@@$$J216YGHIPBDHH@Z) в функции "public: int __clrcall http_client::msg(void)" (?msg@http_client@@$$FQAMHXZ)
1>C:\Users\Jugger\documents\visual studio 2010\Projects\sipc\Debug\sipc.exe : fatal error LNK1120: 22 неразрешенных внешних элементов
1>
1>СБОЙ построения. |
|
0
|