Ok, I have a header file that each of my source files includes:
#ifndef MAIN_H
#define MAIN_H
#include <string>
#include <vector>
#include <sys/socket.h>
using namespace std;
extern string CONFIG_FILE;
struct _msg {
string prefix;
string command;
vector<string> params;
};
struct _channel {
bool bLocalOnly;
string name;
vector<string> users;
string mode;
string topic;
vector<string> banlist;
};
struct _user { //List of all clients on the network
string username;
string host;
string nick;
string mode;
};
struct _server { //List of all servers in the network
string name;
int hopcount;
};
struct _route { //For message routing to clients and servers
bool bIsClient;
string dest;
string nexthop;
int metric;
};
//Lines
struct _oline { //Operator Lines
string host;
string username;
string password;
bool bIsGlobal;
};
struct _kline { //Kill Lines
string usermask;
string reason;
};
struct _dline { //IP Block Lines
string ipmask;
string reason;
};
struct _eline { //Exempt Lines
string hostmask;
string username;
string reason;
};
struct _iline { //Allowed Connection Lines
string ipmask;
string password;
string domainmask;
};
struct _cline { //Outgoing Server Lines
string hostname;
string password;
string servername;
int port;
};
struct _nline { //Incoming Server Lines
string hostname;
string password;
string servername;
};
struct _pline { //Server Binding Lines
string hostmask;
int port;
};
struct _qline { //Server Disallow Lines
string server;
string reason;
};
struct _uline { //Privileged Server Lines
string server;
string password;
string reason;
};
struct mline { //Server Line
string hostname;
string description;
};
struct aline { //Admin Line
string provider;
string serverdesc;
string admin;
};
vector<_msg> messages; //<-------Compiler hates these.
vector<_channel> channels;
vector<_user> users;
vector<_server> servers;
vector<_route> routes;
vector<_oline> olines;
vector<_kline> klines;
vector<_dline> dlines;
vector<_eline> elines;
vector<_iline> ilines;
vector<_cline> clines;
vector<_nline> nlines;
vector<_pline> plines;
vector<_qline> qlines;
vector<_uline> ulines;
#endif
I tried to extern them and put them in one of my files, main.cpp. I still get errors. Here is a small sample of the compiler error:
/tmp/ccrPupuq.o: In function `__static_initialization_and_destruction_0':
/usr/include/c++/4.3/ext/new_allocator.h:76: multiple definition of `messages'
/tmp/ccxIyi8l.o:/home/brian/work/dev/sdirc/args.cpp:29: first defined here
/tmp/ccrPupuq.o: In function `__static_initialization_and_destruction_0':
/usr/include/c++/4.3/bits/stl_vector.h:150: multiple definition of `channels'
/tmp/ccxIyi8l.o:/home/brian/work/dev/sdirc/args.cpp:29: first defined here
/tmp/ccrPupuq.o: In function `__static_initialization_and_destruction_0':
/usr/include/c++/4.3/bits/stl_construct.h:129: multiple definition of `users'
/tmp/ccxIyi8l.o:/usr/include/c++/4.3/bits/stl_vector.h:109: first defined here
/tmp/ccrPupuq.o: In function `__static_initialization_and_destruction_0':
/usr/include/c++/4.3/bits/stl_construct.h:104: multiple definition of `servers'
When I remove the vector statements, everything works fine. The point of the vectors is to replace my linked list code that is buggy and unreliable.