problem when compiling multiple source files

When I compile (that is to say, try to compile) two .h and two .cpp files into a same program, in Borland C++ 5.5, I get an "unresolved external" error. Let me show what causes the error:

I made a program with about 500 lines and split it into several files, whose contents are:

main.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef MAIN_H
#define MAIN_H
using namespace std;

int askInt();
string intHexToString(int);

void help();

void initQuestions();
void add();

void questionsRandom();
void questionsLevel();
void questionsMain(int,int);
bool checkQuestion(int,int);
int drawQuestion(int);
int main();

#endif 


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>

#include "main.h"
#include "settings.h"

/*implementation of the functions declared in main.h:
int askInt();
string intHexToString(int);
void help();
void initQuestions();
void add();
void questionsRandom();
void questionsLevel();
void questionsMain(int,int);
bool checkQuestion(int,int);
int drawQuestion(int);
int main();
*/


settings.h
1
2
3
4
5
6
7
8
9
10
11
#ifndef SETTINGS_H
#define SETTINGS_H

#define SETTINGS_FILE_LOCATION "settings.dat"
#define SETTINGS_ENTRY_EXPECTED_LENGTH 6

int loadSettings(int,string);
void editSettings(int,string,int);
int handleSettings(int,string,string,int,int);

#endif 


settings.cpp
1
2
3
4
5
6
7
#include "settings.h"

/*implementation of the functions declared in settings.h:
int loadSettings(int,string);
void editSettings(int,string,int);
int handleSettings(int,string,string,int,int);
*/


When I type in the command line
bcc32 main.cpp

I get the following output:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
main.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external 'handleSettings(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int)' referenced from C:\USERS\USU-RIO\DESKTOP\SUPERTESTE\MAIN.OBJ


I can't figure out what's wrong with my code. When I had a single file main.cpp the program would compile perfectly, without any error or warning, but now I can't make it work.

I would enormously appreciate your help concerning how I can make my program compile successfully.
Thanks in advance.
Remove "int main()" from main.h

Put "#include <string>" in main.h and not in main.cpp since it is firsted used in the definition file.

Put "#include <string>" in settings.h along with the std namespace.





Borland? People still use that?

Anyway...

double check your handleSettings function and make sure the parameter list matches the prototype exactly.

My guess is you changed one of the parameters or added/removed one. Or you changed the return type... or you misspelled the function name. Something about your function implementation is different from your prototype.
IHARROLD: I did all you told me to do but the problem continues.
DISCH: the parameter list does match the prototype. As I said before, when I had a single file main.cpp everything would work, so the problem almost certainly lies in the fact that my code was split into multiple files.
What is compiler error did it change? Also try reordering the headers in main.cpp:

"#include "settings.h"
#include "main.h"
"
I.e. a method in main.cpp (as defined by main.h) is using functionality in settings.h before it is implemented.
Last edited on
iharold: I caught your idea of putting #include <string> in the header files and did the same to iostream, fstream, sstream, and vector. Next, I entered in the command line
bcc32 main settings
instead of
bcc32 main
.

GUESS WHAT? IT WORKED!

Thanks iharrold and Disch for the interest and help.
I'm kind of amazed that people still actually use the commandline directly.

Get yourself an IDE. Save yourself some headaches
Topic archived. No new replies allowed.