Using multiple files in Geany/gnuc

Hi there,

at school im learning C++ with Visual Studio and we have now comed to classes within multiple files. At home I prefer using Geany with gnuc and thereby I tried to compile the same three files I have succesfully tested with Windows, but it won't work. This is the first error-message (they are all of the same kind):

 
main.cpp:(.text+0x19): undefined reference to 'PiggyBank::init(int)'

Seems like if the other two files weren't included right, doesn't it?
These are the files (unnecessary code is replaced by '...'):

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
///// main.cpp -------------------------------
// -------------------------------------------
#include <iostream>
#include "PiggyBank.h"
using namespace std;

int main()
{
...
}
// -------------------------------------------

///// PiggyBank.h ----------------------------
// -------------------------------------------
#ifndef PIGGYBANK_H
#define PIGGYBANK_H

class PiggyBank
{
private:
	int c1, c10, c50, c100, max;
	bool broken;

public:
	void init (int _max);
	int add1Cents (int insert);
        ...
};

#endif
// -------------------------------------------

///// PiggyBank.cpp --------------------------
// -------------------------------------------
include "PiggyBank.h"

void PiggyBank::init (int _max)
{
...						
}

...
// ------------------------------------------- 

They are all in the same folder. Has anyone an idea what the problem could be? I would be very grateful for beeing able to continue coding with Linux. Thanks in advance.


- Kay
im not quite sure how to add files to geany but if you do it via command line:
g++ main.cpp PiggyBank.cpp -o piggybank
whenever i have multiple c++ files i just use make however. you write the commands you want in a special script called a makefile, then just run make
Topic archived. No new replies allowed.