I'm trying to compile some .cpp files from an old open source project that no longer has a support community. There are about 15 .cpp files in the project and several of them use a one common file called config.cpp. I compile the c++ source code using a make file which runs a command like this:
g++ -g -c -Wall -pedantic -ansi esms.cpp
However this gives me the several errors like this: esms.cpp:234: error: 'the_config' was not declared in this scope
I checked the esms.cpp file and it has the following includes:
#include "game.h"
#include "config.h"
#include "tactics.h"
#include "report_event.h"
#include "teamsheet_reader.h"
#include "cond.h"
#include "util.h"
#include "mt.h"
#include "anyoption.h"
#include "cond_utils.h"
#include "config.h"
#include "comment.h"
I also checked the config.h file and found the following in the file:
class config
{
public:
void load_config_file(string filename);
string get_config_value(string key);
void set_config_value(string key, string value);
int get_int_config(string key, int dflt);
friend config& the_config(void);
private:
config()
{}
config(const config& rhs);
config& operator= (const config& rhs);
map<string, string> config_map;
};
Then I checked the config.cpp file and found the declaration for the_config:
#include <cstdio>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <cctype>
#include "config.h"
#include "util.h"
// get a reference to a static config (a singleton)
config& the_config(void)
{
static config tcfg;
return tcfg;
}
So "the_config" appears to be defined in the config.h and config.cpp files, but for some reason the esms.cpp file doesn't think this is declared. I tried moving the method to the esms.cpp file and removing it from the config.cpp file but then other cpp files that depend on the config.cpp file started getting errors.
How do I make the esms.cpp file recognize that "the_config" is defined in the config.cpp to fix the scope error?
Thanks for your help! I hope this question makes sense, I'm just getting started with C++