Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 5.00/5: Рейтинг темы: голосов - 5, средняя оценка - 5.00
0 / 0 / 0
Регистрация: 21.02.2020
Сообщений: 24
1

Курсач, выводит ошибку LNK2019

03.04.2020, 08:59. Показов 942. Ответов 2

Author24 — интернет-сервис помощи студентам
Выдает ошибку
Ошибка LNK2019 ссылка на неразрешенный внешний символ _main в функции "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
#include <iostream>
#include "math.h"
#include "conio.h"
#include "Windows.h"
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <cstdlib>
#include <clocale>
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------
// отрисовка меню
void ToDrawMenu()
{
    HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD position;
    position.X = 35;
    position.Y = 5;
    SetConsoleCursorPosition(hstdout, position);
    std::cout << "1) Заставка." << endl;
    position.X = 35;
    position.Y = 7;
    SetConsoleCursorPosition(hstdout, position);
    std::cout << "2) Калькулятор" << endl;
    position.X = 35;
    position.Y = 9;
    SetConsoleCursorPosition(hstdout, position);
    std::cout << "3) Игра" << endl;
    position.X = 35;
    position.Y = 11;
    SetConsoleCursorPosition(hstdout, position);
    std::cout << "4) Об авторе" << endl;
    position.X = 35;
    position.Y = 13;
    SetConsoleCursorPosition(hstdout, position);
    std::cout << "5)Выход" << endl;
}
 
//---------------------------------------------------------------------------------------------------------------------------------------
// заставка
void ToAnimation()
{
    system("cls");
    int index = 150;
    int delta = 1;
    do {
        HWND hwn = GetConsoleWindow();
        HDC hdc = GetDC(hwn);
        HPEN pen = CreatePen(PS_DASHDOT, 2, RGB(100, 11, 125));
        HBRUSH brush = CreateSolidBrush(RGB(129, 67, 90));
        HPEN pen1 = CreatePen(PS_DASH, 2, RGB(200, 34, 147));
        SelectObject(hdc, pen);
        SelectObject(hdc, brush);
        Ellipse(hdc, 650 - index, 480 - index, 250 + index, 160 + index);
        SelectObject(hdc, pen1);
        Ellipse(hdc, 550 - index, 480 - index, 150 + index, 160 + index);
        if (index > 500)
            delta = -1;
        if (index < 150)
            delta = 1;
        index += delta;
        Sleep(3);
    } while (!_kbhit());
    system("pause");
}
 
//---------------------------------------------------------------------------------------------------------------------------------------
// калькулятор
double Suma(double a1, double a2) {
    double sum = a1 + a2;
    //  std::cout << a1 << "+" << a2 << "=" << sum << endl;
    return sum;
}
double Razno(double a1, double a2) {
    double razn = a1 - a2;
    //  std::cout << a1 << "-" << a2 << "=" << razn << endl;
    return razn;
}
double Proizv(double a1, double a2) {
 
    double proiz = a1 * a2;
    //  std::cout << a1 << "*" << a2 << "=" << proiz << endl;
    return proiz;
}
double Dele(double a1, double a2) {
    double del = a1 / a2;
    //  std::cout << a1 << "/" << a2 << "=" << del << endl;
    return del;
}
 
int Calculate() {
    double a1, a2, res;
    char b;
    setlocale(LC_ALL, "Rus");
    cout << ("Введите два числа:") << endl;
    cin >> a1 >> a2;
    cout << ("Выберите необходимую операцию") << endl;
    cout << ("'+' - cложение") << endl;
    cout << ("'-' - вычитание") << endl;
    cout << ("'/' - деление") << endl;
    cout << ("'*' - умножение") << endl;
    cin >> b;
    switch (b) {
    case '+':
        res = Suma(a1, a2);
        break;
    case '-':
        res = Razno(a1, a2);
        break;
 
    case '*':
        res = Proizv(a1, a2);
        break;
    case '/':
        res = Dele(a1, a2);
        break;
 
    default:
        std::cout << "Выберите из списка предложенных\n";
        system("pause");
        return 1;
    }
    cout << a1 << b << a2 << "=" << res << endl;
    system("pause");
    return 0;
}
//---------------------------------------------------------------------------------------------------------------------------------------
// игра
//-----------------------------------------------------------------------------------------------------------------------
//объявление глобальных переменных
void initgame();
void fulldraw();
void redraw();
void input();
void move_bots(COORD&);
void move_win(COORD&);
void gameover();
void gamewin();
void move_gold(COORD&);
using namespace std;
 
vector<string> world =
{ "##########################",
    "#                        #",
    "#       #      #         #",
    "#       #   G  #         #",
    "#       ##################",
    "#       #      #         #",
    "#   F   #      #         #",
    "#                 F      #",
    "#       #      #         #",
    "#       #      #         #",
    "#       #      #         #",
    "#           P            #",
    "##########################"
};
COORD player; //игрок
COORD gold;   //золото
vector<COORD> foes; //враг
vector<COORD> g;
HANDLE out;
const COORD directions[] = { {0,1}, {1,0},{0,-1}, {-1,0} };
int time_numerator, time_denominator;
bool gameplay = true;
 
bool operator ==(COORD left, COORD right)
{
    return left.X == right.X && left.Y == right.Y;
}
 
bool operator !=(COORD left, COORD right)
{
    return left.X != right.X || left.Y != right.Y;
}
 
//-----------------------------------------------------------------------------------------------------------------------
int Game()
{
    COORD E = { 12, 3 };
    world[E.Y][E.X] = 'G';
 
    initgame();
    fulldraw();
 
    while (gameplay)
    {
        redraw();
        if (E == player) gamewin();
 
        Sleep(100);
        input();
 
        if (++time_numerator > time_denominator)
        {
            time_numerator -= time_denominator;
            for (auto& foe : foes)
            {
                move_bots(foe);
                if (foe == player)
                    gameover();
            }
            for (auto& G : g)
            {
                move_win(G);
            }
        }
    }
    return 0;
}
 
//-----------------------------------------------------------------------------------------------------------------------
//обзначение направления
void input()
{
    if (GetAsyncKeyState(VK_UP) && world[player.Y - 1][player.X] == ' ')
        --player.Y;
    if (GetAsyncKeyState(VK_DOWN) && world[player.Y + 1][player.X] == ' ')
        ++player.Y;
    if (GetAsyncKeyState(VK_LEFT) && world[player.Y][player.X - 1] == ' ')
        --player.X;
    if (GetAsyncKeyState(VK_RIGHT) && world[player.Y][player.X + 1] == ' ')
        ++player.X;
    for (auto& foe : foes)
        if (foe == player)
            gameover();
}
 
//-----------------------------------------------------------------------------------------------------------------------
//координаты игрока, золота, врагов
void redraw()
{
    static COORD p = { 1,1 }, g = { 1,1 };
    static vector<COORD> f;
    if (player != p)
    {
        SetConsoleCursorPosition(out, p);
        cout << " ";
        p = player;
        SetConsoleCursorPosition(out, p);
        cout << "P";
    }
    if (gold != g)
    {
        SetConsoleCursorPosition(out, g);
        cout << " ";
        g = gold;
        SetConsoleCursorPosition(out, g);
        cout << "G";
    }
    for (int i = 0; i < foes.size(); ++i)
        if (i >= f.size())
        {
            f.push_back(foes[i]);
            SetConsoleCursorPosition(out, foes[i]);
            cout << "F";
        }
        else if (f[i] != foes[i])
        {
            SetConsoleCursorPosition(out, f[i]);
            cout << " ";
            f[i] = foes[i];
            SetConsoleCursorPosition(out, f[i]);
            cout << "F";
        }
}
 
//-----------------------------------------------------------------------------------------------------------------------
//чтобы поле стояло на одном месте
void fulldraw()
{
    SetConsoleCursorPosition(out, { 0,0 });
    for (auto row : world)
        cout << row << endl;
}
 
//-----------------------------------------------------------------------------------------------------------------------
//движок игры
void initgame()
{
    out = GetStdHandle(STD_OUTPUT_HANDLE);
    time_numerator = 3;     //скрость увеличим, быстрее враги
    time_denominator = 5;   //скорость увеличим, замедлим врагов
    for (SHORT i = 0; i < world.size();
        ++i)        //считывается поле и его координаты
        for (SHORT j = 0; j < world[i].size(); ++j)
            switch (world[i][j])
            {
            case 'G':
                gold = { j, i };
                world[i][j] = ' ';
                break;
            case 'P':
                player = { j, i };
                world[i][j] = ' ';
                break;
            case 'F':
                foes.push_back({ j, i });
                world[i][j] = ' ';
                break;
            default:
                break;
            }
}
 
//-----------------------------------------------------------------------------------------------------------------------
struct astar
{
    int x, y;
    int dist;
    int initial_dx, initial_dy;
};
 
//-----------------------------------------------------------------------------------------------------------------------
struct best_way
{
    constexpr bool operator()(const astar& left, const astar& right) const
    {
        return left.dist >
            right.dist;//выбирает наихудший фактор, чтобы глубже зашнуровать его в очереди
    }
};
 
//-----------------------------------------------------------------------------------------------------------------------
void move_bots(COORD& foe)
{
    vector<vector<bool> > visited(world.size(), vector<bool>(world[0].size(),
        false));
    std::priority_queue <astar, std::vector<astar>, best_way > stars;
    visited[foe.Y][foe.X] = true;
    for (int i = 0; i < 4; ++i)
    {
        int x = foe.X + directions[i].X;
        int y = foe.Y + directions[i].Y;
        if (world[y][x] == ' ' && !visited[y][x])
        {
            astar new_node = { x, y, 0 , directions[i].X,  directions[i].Y };
            new_node.dist = abs(new_node.x - player.X) + abs(new_node.y - player.Y);
            stars.push(new_node);
            visited[y][x] = true;
        }
 
    }
    while (!stars.empty())
    {
        if (stars.top().x == player.X && stars.top().y == player.Y)
        {
            foe.X += stars.top().initial_dx;
            foe.Y += stars.top().initial_dy;
            return;
        }
        astar root = stars.top();
        stars.pop();
        for (int i = 0; i < 4; ++i)
        {
            int x = root.x + directions[i].X;
            int y = root.y + directions[i].Y;
            if (world[y][x] == ' ' && !visited[y][x])
            {
                astar new_node = { x, y, 0, root.initial_dx,  root.initial_dy };
                new_node.dist = abs(new_node.x - player.X) + abs(new_node.y - player.Y);
                stars.push(new_node);
                visited[y][x] = true;
            }
 
        }
 
    }
}
 
//-----------------------------------------------------------------------------------------------------------------------
void move_win(COORD& G)
{
    vector<vector<bool> > visited(world.size(), vector<bool>(world[0].size(),
        false));
    std::priority_queue <astar, std::vector<astar>, best_way > stars;
    visited[G.Y][G.X] = true;
    for (int i = 0; i < 4; ++i)
    {
        int x = G.X + directions[i].X;
        int y = G.Y + directions[i].Y;
        if (world[y][x] == ' ' && !visited[y][x])
        {
            astar new_node = { x, y, 0 , directions[i].X,  directions[i].Y };
            new_node.dist = abs(new_node.x - player.X) + abs(new_node.y - player.Y);
            stars.push(new_node);
            visited[y][x] = true;
        }
 
    }
    while (!stars.empty())
    {
        if (stars.top().x == player.X && stars.top().y == player.Y)
        {
            G.X += stars.top().initial_dx;
            G.Y += stars.top().initial_dy;
            return;
        }
        astar root = stars.top();
        stars.pop();
        for (int i = 0; i < 4; ++i)
        {
            int x = root.x + directions[i].X;
            int y = root.y + directions[i].Y;
            if (world[y][x] == ' ' && !visited[y][x])
            {
                astar new_node = { x, y, 0, root.initial_dx,  root.initial_dy };
                new_node.dist = abs(new_node.x - player.X) + abs(new_node.y - player.Y);
                stars.push(new_node);
                visited[y][x] = true;
            }
 
        }
 
    }
}
 
//-----------------------------------------------------------------------------------------------------------------------
//проигрыш
void gameover()
{
    gameplay = false;
    SetConsoleCursorPosition(out, { 30, 10 });
    cout << "GAME OVER";
    while (!GetAsyncKeyState(VK_ESCAPE)) {} //определяет нажимание кнопки выхода
}
 
//-----------------------------------------------------------------------------------------------------------------------
//выигрыш
void gamewin()
{
    gameplay = false;
    SetConsoleCursorPosition(out, { 30, 10 });
    cout << "GAME Win";
    while (!GetAsyncKeyState(VK_ESCAPE)) {}
}
//---------------------------------------------------------------------------------------------------------------------------------------
// Об авторе
void AboutMe()
{
    system("cls");
    HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD position;
    position.X = 30;
    position.Y = 7;
    SetConsoleCursorPosition(hstdout, position);
    cout << "Фамилия : Лисова" << endl;
    position.X = 30;
    position.Y = 10;
    SetConsoleCursorPosition(hstdout, position);
    cout << "Имя : Анастасия" << endl;
    position.X = 30;
    position.Y = 13;
    SetConsoleCursorPosition(hstdout, position);
    cout << "Год и место обучения : 2020 ОмГТУ" << endl;
    position.X = 30;
    position.Y = 16;
    SetConsoleCursorPosition(hstdout, position);
    cout << "Факультет : ФИТиКС" << endl;
    position.X = 30;
    position.Y = 19;
    SetConsoleCursorPosition(hstdout, position);
    cout << "Группа : ПИ-192" << endl;
    system("pause");
}
//---------------------------------------------------------------------------------------------------------------------------------------
// Выход
 
//---------------------------------------------------------------------------------------------------------------------------------------
// Очистка экрана
void SystemClear()
{
    HWND hwn = GetConsoleWindow();
    HDC hdc = GetDC(hwn);
    HPEN pen = CreatePen(PS_DASHDOT, 2, RGB(0, 255, 0));
    HBRUSH brush = CreateSolidBrush(RGB(0, 0, 0));
    SelectObject(hdc, pen);
    SelectObject(hdc, brush);
    Rectangle(hdc, 0, 0, 2000, 2000);
}
//---------------------------------------------------------------------------------------------------------------------------------------
// переходы из меню
void ToViewMenu()
{
    system("cls");
    HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE),
        hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD result;
    COORD position;
    INPUT_RECORD keyBuff;
    ToDrawMenu();
    ReadConsoleInput(hStdin, &keyBuff, 1, &result);
    switch (keyBuff.Event.KeyEvent.uChar.AsciiChar)
    {
    case '1':
    {
        ToAnimation();
        SystemClear();
        break;
    }
    case '2':
        Calculate();
        SystemClear();
        break;
    case '3':
        Game();
        SystemClear();
        break;
    case '4':
        AboutMe();
        SystemClear();
        break;
 
    case '5':
        exit(0);
        break;
    }
}
0
Лучшие ответы (1)
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
03.04.2020, 08:59
Ответы с готовыми решениями:

Как исправить ошибку lnk2019
#include &quot;stdafx.h&quot; #include &lt;stdio.h&gt; #include &lt;math.h&gt; int main() { int a=0; int b=0;...

Исправить ошибку LNK2019: ссылка на неразрешенный внешний символ (InternetCheckConnection и WinAPI)
Создаю простенькое приложение на winapi с кнопкой и полем edit, по нажатию на которую происходит...

Не могу запустить программку компилятор выдаёт ошибку error LNK2019: ссылка на неразрешенный внешний символ
Прошу прощения за глупые вопросы но я новичок в програмировании .Вот моя программка и копия ошибки...

Выводит ошибку MBS6006 "CL.exe" exited with code 2. Как исправить эту ошибку?
#pragma once #include &quot;iostream&quot; #include &quot;conio.h&quot; #include &quot;cmath&quot; #include &lt;string&gt;...

2
"C with Classes"
1646 / 1403 / 523
Регистрация: 16.08.2014
Сообщений: 5,877
Записей в блоге: 1
03.04.2020, 09:13 2
Лучший ответ Сообщение было отмечено Blumix2002 как решение

Решение

Цитата Сообщение от Blumix2002 Посмотреть сообщение
Выдает ошибку
Ошибка LNK2019 ссылка на неразрешенный внешний символ _main в функции "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
нет у тебя в коде ни main, ни invoke_main

Добавлено через 1 минуту
а ошибка эта о том, что ты где то вызываешь функцию которую не определил
0
5231 / 3204 / 362
Регистрация: 12.12.2009
Сообщений: 8,113
Записей в блоге: 2
03.04.2020, 09:31 3
Это все потому, что у тебя не курсач, а г...но, которое ты где-то скопипастил и даже скомпилировать не можешь.
Ознакомься.
0
03.04.2020, 09:31
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
03.04.2020, 09:31
Помогаю со студенческими работами здесь

Выводит ошибку MBS6006 "CL.exe" exited with code 2. Как исправить эту ошибку?
Иногда возникает эта ошибка и не понимаю, мол откуда она. Погуглил - ничего дельного. Подскажите,...

Как исправить ошибку LNK2019
#ifndef MYCLASS_H #define MYCLASS_H #include &lt;QString&gt; #include &lt;QtWidgets&gt; #include &quot;token.h&quot;...

Компилятор выдает ошибку, LNK2019 ссылка на неразрешенный внешний символ
Программа не запускается, где-то ошибка не могу понять где. Помогите найти! Файлы из программы вот...

Как устранить ошибку LNK2019 при подключении библиотеки журналирования log4c?
Здравствуйте! Имеется библиотека log4c (для журналирования событий), использую Visual C++ 2008. ...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
3
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru