Autor Beitrag
Silas
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 478

Windows XP Home
Delphi 2005, RAD Studio 2007, MASM32, FASM, SharpDevelop 3.0
BeitragVerfasst: So 22.04.07 17:59 
Hallo!

Ich habe ein Programm, bei dem der Quellcodeumfang recht groß ist (bzw. wird), und deshalb möchte ich den Code in mehrere Dateien aufteilen.
Ich benutze Dev-C++ und dort habe ich die Möglichkeit, ein Projekt aus beliebig vielen Dateien zu erstellen. Jetzt habe ich aber ein paar Klassen in einer Datei deklariert und möchte sie in einer anderen verwenden. Das funktioniert aber nicht, weil der Compiler dann die Klassen nicht kennt. Wenn ich die Dateien nicht in mein Projekt einbinde, sondern jeweils mit #include, dann werden sie nicht mehr automatisch mitübersetzt.
Gibt es da irgendeine Lösung (Ich bin sicher, das ist irgend ein Anfängerproblem)?

Danke
Silas

_________________
Religionskriege sind nur Streitigkeiten darüber, wer den cooleren imaginären Freund hat ;-)
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 22.04.07 18:41 
Die Typische Anwendung für eine Makefile ;-)
ausblenden Makefile
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
CFLAGS= -std=c99 -pedantic -Wall -Wpointer-arith -Wstrict-prototypes -O9 -g

all: appname1 appname2

appname1: ../bin/main.o ../bin/class1.o ../bin/class2.o ../bin/class3.o
  gcc $(CFLAGS) -o ../bin/appname1 ../bin/main.o ../bin/class1.o ../bin/class2.o ../bin/class3.o -I. -lm

../bin/main.o: main.c main.h class1.h class3.h
  gcc $(CFLAGS) -c main.c -o ../bin/main.o

../bin/class1.o: class1.c class1.h
  gcc $(CFLAGS) -c class1.c -o ../bin/class1.o
  
../bin/class2.o: class2.c class2.h class1.h
  gcc $(CFLAGS) -c class2.c -o ../bin/class2.o

../bin/class3.o: class3.c class3.h
  gcc $(CFLAGS) -c class3.c -o ../bin/class3.o

Und dann eben ganz normal die Header und Source-Files ...
ausblenden main.c
1:
2:
3:
#include "main.h"

//Foo bar baz ...

ausblenden main.h
1:
2:
3:
4:
#include "class1.h"
#include "class3.h"

//Exported stuff of main.c

ausblenden class1.c
1:
2:
3:
#include "class1.h"

//Foo bar baz ...

ausblenden class1.h
1:
2:
3:
#include <stdio.h>

//Exported stuff of class1.c

ausblenden class2.c
1:
2:
3:
#include "class2.h"

//Foo bar baz ...

ausblenden class2.h
1:
2:
3:
4:
#include <stdio.h>
#include "class1.h"

//Exported stuff of class2.c

ausblenden class3.c
1:
2:
3:
#include "class3.h"

//Foo bar baz ...

ausblenden class3.h
1:
2:
3:
4:
#include <stdio.h>
#include "class1.h"

//Exported stuff of class3.c

Zu "compilieren" mit make ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Silas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 478

Windows XP Home
Delphi 2005, RAD Studio 2007, MASM32, FASM, SharpDevelop 3.0
BeitragVerfasst: Mo 23.04.07 15:37 
Danke BenBE!! :)

Jetzt weiß ich endlich, wofür's eigentlich Headerfiles gibt :think: .
Funktioniert gut, aber ein Makefile brauch ich nicht, das managt Dev-Cpp automatisch.

_________________
Religionskriege sind nur Streitigkeiten darüber, wer den cooleren imaginären Freund hat ;-)