0 / 0 / 1
Регистрация: 24.08.2012
Сообщений: 14
|
|
|
|
Ошибка при компиляции в Code::Blocks
28.10.2012, 13:32. Показов 1488. Ответов 1
Помогите решить ошибки при компиляции
Код:
main.cpp
| 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
|
#include <iostream>
#include <string>
#include <signal.h>
#include <string.h>
#include <syslog.h>
// --
#include "wheel.h"
#define DEBUG
#define MAXNAME 31
static Wheel *serv;
#ifndef DEBUG
static void clean_exit(int sig);
#endif
//using namespace std;
/***************************************************************************/
int main(int argc, char *argv[]){
string d_name = (strrchr(argv[0], '/') + 1);
/* Инициализация основных объектов */
try{
if(d_name.length() > MAXNAME) throw (string)"Main:d_name.length()!";
// serv = new Wheel("serv_tm"); // (perent Daemon)
// serv->Command("start");
serv = new Wheel(d_name); // (perent Daemon)
serv->Command((argc > 1) ? argv[1] : "");
/* Инициализация основных объектов */
serv->Init();
#ifndef DEBUG
/* Настройка системных сигналов */
signal(SIGINT, clean_exit);
signal(SIGUSR1, clean_exit);
signal(SIGQUIT, clean_exit);
signal(SIGTERM, clean_exit);
signal(SIGPIPE, SIG_IGN);
#endif
/* Ответвляемся и завершаем родительский процесс */
serv->Daemonize();
/* Запуск */
serv->Run();
// --
// -------------------------------------------------------------------------
}catch( string e){
#ifdef DEBUG
cout << "FATAL_ERROR " << e << endl << "Exit." << endl;
#endif
syslog(LOG_LOCAL0|LOG_INFO|LOG_ERR, "FATAL_ERROR: %s", e.c_str());
closelog();
}
return EXIT_FAILURE;
}// End main ----------------------------------------------------------------
/***************************************************************************/
// Обработчики сигналов
#ifndef DEBUG
static void clean_exit(int sig){
serv->Exit(sig);
exit(EXIT_SUCCESS);
}// End clean_exit
#endif
/***************************************************************************/ |
|
wheel.cpp
| 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
| #include <syslog.h>
#include <string.h>
#include <signal.h>
#include <iostream>
#include <errno.h>
// --
#include "wheel.h"
#include "device.h"
#include "config.h"
#include "dbwriter.h"
// --
#define DEBUG
// ---------------------------------
using namespace std;
// -------------------------------------------------------------------------
Wheel::Wheel(string nameserv) : Daemon(nameserv){
// string nameserv = "serv_s"; // Уникальное имя сервиса VARCHAR(32)
#ifdef DEBUG
cout << "\nWheel::Wheel(" << nameserv << ") *******************************************************************\n\n";
#endif
maxdev = 0;
curdev = -1;
trt = NULL;
// Получаем конфигурацию для данного сервера ( параметров сети, оборудования и имена таблиц )
cfg = new Config(nameserv); // при неудаче исключение FError(msg)
#ifdef DEBUG
cout << "Wheel >> NetConf: " << cfg->getHost() << " PS: " << cfg->getPort() << " TM: " << cfg->getTimeAut() << endl;
#endif
}// End Wheel
//**************************************************//
void Wheel::Init(void){
/* Инициализация основных объектов */
syslog(LOG_LOCAL0|LOG_INFO, "Init.");
// Подключение
#ifdef DEBUG
cout << "Connect...\n";
#endif
int cn = 10; // попытки
do{
if(trt) delete trt;
trt = new TransPort(cfg->getHost(), cfg->getPort(), cfg->getTimeAut() );
if(trt->status() > 0) break;
#ifdef DEBUG
cout << "WARNING - " << cn << " : " << trt->getMsg();
#endif
syslog(LOG_LOCAL0|LOG_INFO, "WARNING: Init: %s", trt->getMsg().c_str());
sleep(2);
if(!--cn) throw (string)trt->getMsg();
} while(trt->status() < 1);
//-------------------------------------
// Выделяем память для указателей на виртуальные устройства
maxdev = cfg->maxDevice();
#ifdef DEBUG
cout << "MaxDev: " << maxdev << endl;
#endif
dd = new Device* [maxdev];
if(!dd) throw (string)"Serv >> Memory - failed";
//-------------------------------------
// Инициализируем виртуальные устройства
#ifdef DEBUG
cout << "Init Device...\n";
#endif
// curdev = 0; dd[curdev] = new Device( cfg, trt ); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
for(curdev = 0;cfg->Next(); curdev++){
dd[curdev] = new Device( cfg, trt );
#ifdef DEBUG
cout << dd[curdev]->getMsg() << endl;
#endif
}
//-------------------------------------
// Инициализируем "самописец"
#ifdef DEBUG
cout << "Init DBWriter...\n";
#endif
dbwr = new DBWriter(cfg);
#ifdef DEBUG
cout << dbwr->getMsg() << endl;
#endif
}// End Init
// -------------------------------------------------------------------------
/***************************************************************************/
/* Запуск */
void Wheel::Run(void){// Цикл опроса
#ifdef DEBUG
cout << "\n\tWheel::Run()\n\n";
//int pid = 7; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#endif
syslog(LOG_LOCAL0|LOG_INFO, "Run.");
// int timclear = 3600 * 27;
while(pid){
#ifdef DEBUG
cout << "New" << endl;
#endif
int rez = 0;
for( curdev = 0; curdev < maxdev; curdev++){
rez = dd[curdev]->Refresh(0);
//cout << endl << "MainDevRefreshRez: " << rez << endl;
//-------------------------------------
// if((rez == E_RCV)||(rez == E_SND)){// Через 10 минут Повторное Подключение
if(rez == E_SOCKET){// Повторное Подключение
#ifdef DEBUG
cout << "ReConnect..." << endl;
#endif
int cn = 20000; // попытки
do{
if(trt) delete trt;
trt = new TransPort(cfg->getHost(), cfg->getPort(), cfg->getTimeAut());
if(trt->status() > 0) break;
string mess = trt->getMsg();
#ifdef DEBUG
cout << "WARNING - " << cn << " : " << mess << " - " << endl;
#endif
syslog(LOG_LOCAL0|LOG_INFO, "WARNING: Reconnect: %s", mess.c_str());
sleep(10);
if(!--cn) throw (string)mess;
} while(trt->status() < 1);
#ifdef DEBUG
cout << "OK." << endl;
#endif
}
//-------------------------------------
if(!dbwr->Write(dd[curdev])){
syslog(LOG_LOCAL0|LOG_INFO, "ERROR: DBWriter: %s", dbwr->getMsg().c_str());
}
//-------------------------------------
} // for
//-------------------------------------
// if(timclear >= (3600 * 24)){
// if(!dbwr->oldClear()){
//cout << "Error." << dbwr->getMsg() << endl;
// syslog(LOG_LOCAL0|LOG_ERR, "ERROR: %s", dbwr->getMsg().c_str());
// }
// timclear = 0;
// }// if timclear
// timclear++;
#ifdef DEBUG
cout << "End. Ждем: " << (cfg->getTCicle() / 1000 )<< " сек.\n";
#endif
usleep( cfg->getTCicle() * 1000); // ждем милисекундах
}// while
}// End Run
/***************************************************************************/
void Wheel::ErrLog(string st){
syslog(LOG_LOCAL0|LOG_INFO,"ERROR: %s", st.c_str());
#ifdef DEBUG
cout << "ERROR: " << st.c_str() << endl;
#endif
}
/***************************************************************************/ |
|
wheel.h
| 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
| #ifndef Serv_class
#define Serv_class
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <iostream>
// --
#include "daemon.h"
#include "defs.h"
#include "config.h"
#include "transport.h"
#include "device.h"
#include "dbwriter.h"
//----------------------------------------------------------------
using namespace std;
//----------------------------------------------------------------
class Wheel : public Daemon{
public:
Wheel(string);
void Init(void);
void Run(void);
void ErrLog(string);
protected:
//private:
// --
int maxdev, curdev;
Config *cfg;
Device **dd;
TransPort *trt;
DBWriter *dbwr;
};
//----------------------------------------------------------------
#endif |
|
Лог:
| C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| obj/Debug/main.o||In function `main':|
/home/user/OPC/server_sd/main.cpp|18|multiple definition of `main'|
obj/Debug/main.o:/home/user/OPC/server_sd/main.cpp|18|first defined here|
obj/Debug/wheel.o||In function `Wheel':|
/home/user/OPC/server_sd/wheel.cpp|25|multiple definition of `Wheel::Wheel(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'|
obj/Debug/wheel.o:/home/user/OPC/server_sd/wheel.cpp|25|first defined here|
obj/Debug/wheel.o||In function `Wheel::Init()':|
/home/user/OPC/server_sd/wheel.cpp|42|multiple definition of `Wheel::Init()'|
obj/Debug/wheel.o:/home/user/OPC/server_sd/wheel.cpp|42|first defined here|
obj/Debug/wheel.o||In function `Wheel::Run()':|
/home/user/OPC/server_sd/wheel.cpp|107|multiple definition of `Wheel::Run()'|
obj/Debug/wheel.o:/home/user/OPC/server_sd/wheel.cpp|107|first defined here|
obj/Debug/wheel.o||In function `Wheel::ErrLog(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':|
/home/user/OPC/server_sd/wheel.cpp|171|multiple definition of `Wheel::ErrLog(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'|
obj/Debug/wheel.o:/home/user/OPC/server_sd/wheel.cpp|171|first defined here|
obj/Debug/wheel.o||In function `Wheel':|
/home/user/OPC/server_sd/wheel.cpp|25|multiple definition of `Wheel::Wheel(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'|
obj/Debug/wheel.o:/home/user/OPC/server_sd/wheel.cpp|25|first defined here| |
|
0
|