PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : compilieren von mehreren Dateien "makefile"



zini2001
07-04-2005, 22:38
hallo ....
folgendes programm möchte ich auf mehrere dateien aufteilen.
eine main.c, graphmain.c und graphmain.h .

original: (nach dem tut von http://enchantia.com/software/graphapp/)

#include <stdio.h>
#include "graphapp.h"
//#include "graphmain.h" !!!EDIT

void redraw_it(Window *w, Graphics *g);
int main(int argc, char *argv[])
{
App *app = new_app(argc, argv);
Window *w = new_window(app,rect(20,20,350,250),"test",STANDARD_WINDOW);

on_window_redraw(w, redraw_it);

show_window(w);
main_loop(app);
return 0;
}
void graph(Window *w, Graphics *g)
{
new_label(w,rect(0,0,100,30),"hallo zini",ALIGN_LEFT);
}
mit diesem makefile kann ich das programm erzeugen und klappt!
makefile:
CC = gcc -g

APP_PATH = /home/warnekes/app/src
APP_LIB = app

X11 = /usr/X11R6
X11LIB = $(X11)/lib

LIBS = -lX11 -lc -lm
DYNALINK = -Xlinker -rpath -Xlinker $(APP_PATH)

CFLAGS = -I$(APP_PATH)
DYNAMIC = -L$(APP_PATH) -l$(APP_LIB) -L$(X11LIB) $(LIBS) $(DYNALINK)
STATIC = $(APP_PATH)/lib$(APP_LIB).a -L$(X11LIB) $(LIBS)

TARGET = main
SRC = main.o
static: $(SRC)
# Creating the static version.
# Try "make dynamic" for a smaller executable size.
$(CC) $(CFLAGS) $(SRC) $(STATIC) -o $(TARGET)

dynamic: $(SRC)
# Creating the dynamic version.
# Try "make static" if this has problems.
$(CC) $(CFLAGS) $(SRC) $(DYNAMIC) -o $(TARGET)



test: main.o
$(CC) $(CFLAGS) $(SRC) $(DYNAMIC) -o $(TARGET)

clean:
rm -f core *.o $(TARGETS)

main.c:

#include <stdio.h>
#include "graphmain.h"

void redraw_it(Window *w, Graphics *g);
int main(int argc, char *argv[])
{
App *app = new_app(argc, argv);
Window *w = new_window(app,rect(20,20,350,250),"test",STANDARD_WINDOW);

on_window_redraw(w, redraw_it);

show_window(w);
main_loop(app);
return 0;
}
graphmain.c:



#include "graphmain.h"

void graph(Window *w, Graphics *g)
{
new_label(w,rect(0,0,100,30),"hallo zini",ALIGN_LEFT);
}
grapmain.h:

#ifndef _graphmain_h
#define _graphmain_h

#include <stdio.h>
#include "graphapp.h" // !!!EDIT

void redraw_it(Window *w, Graphics *g);

#endif

nach div. anleitungen und makefiles hab ich mir das hier zusammengebastelt.
makefile: (dieses makefile hab ich mir zusammen geklaut)


CC = gcc -g

APP_PATH = /home/warnekes/app/src
APP_LIB = app

X11 = /usr/X11R6
X11LIB = $(X11)/lib

LIBS = -lX11 -lc -lm
DYNALINK = -Xlinker -rpath -Xlinker $(APP_PATH)

CFLAGS = -I$(APP_PATH)
DYNAMIC = -L$(APP_PATH) -l$(APP_LIB) -L$(X11LIB) $(LIBS) #$(DYNALINK)
STATIC = $(APP_PATH)/lib$(APP_LIB).a -L$(X11LIB) $(LIBS)

TARGET = main
SRC = main.o graphmain.o

static: $(SRC)
# Creating the static version.
# Try "make dynamic" for a smaller executable size.
$(CC) $(CFLAGS) $(SRC) $(STATIC) -o $(TARGET)

dynamic: main.o
# Creating the dynamic version.
# Try "make static" if this has problems.
$(CC) $(CFLAGS) $(SRC) $(DYNAMIC) -o $(TARGET)

main.o: main.o graphmain.h
$(CC) -c $(CFLAGS) main.o main.c $(DYNAMIC)

graphmain.o: main.o graphmain.h
$(CC) -c $(CFLAGS) graphmain.o graphmain.c $(DYNAMIC)


clean:
rm -f core *.o $(TARGETS)


fehlermeldung:


warnekes@henderson:~/FHH/sse-ssn/test_uebersicht> make
gcc -O -I/usr/X11R6/include -I/home/warnekes/app/src -c -o main.o main.c
In file included from main.c:2:
graphmain.h:7: error: parse error before '*' token
main.c: In function `main':
main.c:7: error: `App' undeclared (first use in this function)
main.c:7: error: (Each undeclared identifier is reported only once
main.c:7: error: for each function it appears in.)
main.c:7: error: `app' undeclared (first use in this function)
main.c:8: error: `Window' undeclared (first use in this function)
main.c:8: error: `w' undeclared (first use in this function)
main.c:8: error: `STANDARD_WINDOW' undeclared (first use in this function)
make: *** [main.o] Fehler 1
warnekes@henderson:~/FHH/sse-ssn/test_uebersicht>


mir ist nicht ganz klar wie ich die makefiles zu benutzen habe.
wie und was muß ich im makefile umschreiben, um mehrere dateien einzulinken?
mag mir jemand helfen?

gruß

Detrius
07-04-2005, 23:32
Die Fehlermeldungen beim Kompilieren zeigen an, dass hier so einiges nicht definiert wurde. Was z.b. ist App? Das wird niergendwo definiert. ;)

Du hast in der ersten Version von main.c schon ein #include "graphmain.h". In der zweiten Version legst Du einen Header mit gleichem Namen nochmal selbst an. Das ist doch etwas komisch. Gibt es vllt. schon ein bestehendes graphmain.h, in dem die fehlenden Funktionen und Datentypen definiert sind? Zwei verschiedene Dateien gleichen Namens per #include "name.h" einbinden zu wollen, geht nicht so gut.

zini2001
09-04-2005, 08:01
ja hast recht!!
im ersten programm, also in der main.c in der alles drin steht muß es nicht "graphmain.h" sonder "graphapp.h" lauten.
damit verschwinden natürlich auch die fehlermeldungen wie oben gezeigt.

jetzt besteht aber imer noch das problem, die main.c aufzuteilen, in die dateien:
-main.c
-graphmain.c : window funktionen mit leben füllen
-graphmain.h : deklaration der window funktionen

und das passende makefile zu basteln. den mit dem oben gezeigten klappt es nach wie vor nicht.

mir ist der aufbau noch nicht so richtig klar.
in dem einen tutorial hier im forum hab ich gelesen, erst die einzelnen *.c dateien in *.o ohne compilieren, und dann dem linker beide *.o dateien zu über geben.(komisch geschrieben.....)
etwa so:



main: graphmain.o main.o
gcc -g -o main graphmain.o main.o -Wall -L/usr/X11R6/lib -lX11 -lc -lm

main.o: main.c graphmain.h
gcc -c -o main.o main.c -Wall -I/home/warnekes/app/src

graphmain.o: graphmain.c graphmain.h
gcc -c -o graphmain.o graphmain.c -Wall -I/home/warnekes/app/src

mit der konstellation kommt dieser fehler:


make
gcc -g -o main graphmain.o main.o -Wall -L/usr/X11R6/lib -lX11 -lc -lm
graphmain.o(.text+0x2a): In function `graph':
/home/warnekes/Documents/FHH/sse-ssn/test_uebersicht/graphmain.c:5: undefined reference to `app_new_rect'
graphmain.o(.text+0x37):/home/warnekes/Documents/FHH/sse-ssn/test_uebersicht/graphmain.c:5: undefined reference to `app_new_label'
main.o(.text+0x27): In function `main':
/home/warnekes/Documents/FHH/sse-ssn/test_uebersicht/main.c:7: undefined reference to `app_new_app'
main.o(.text+0x5a):/home/warnekes/Documents/FHH/sse-ssn/test_uebersicht/main.c:8: undefined reference to `app_new_rect'
main.o(.text+0x67):/home/warnekes/Documents/FHH/sse-ssn/test_uebersicht/main.c:8: undefined reference to `app_new_window'
main.o(.text+0x75):/home/warnekes/Documents/FHH/sse-ssn/test_uebersicht/main.c:10: undefined reference to `redraw_it'
main.o(.text+0x7d):/home/warnekes/Documents/FHH/sse-ssn/test_uebersicht/main.c:10: undefined reference to `app_on_window_redraw'
main.o(.text+0x8b):/home/warnekes/Documents/FHH/sse-ssn/test_uebersicht/main.c:12: undefined reference to `app_show_window'
main.o(.text+0x99):/home/warnekes/Documents/FHH/sse-ssn/test_uebersicht/main.c:13: undefined reference to `app_main_loop'
collect2: ld returned 1 exit status
make: *** [graphmain] Fehler 1



mir ist wiegsagt nicht klar wie ich verschiedene *.c dateien mit ihren zugehörigen *.h dateien und einer haupt datei main.c kompilieren kann.

Joghurt
09-04-2005, 12:24
Du musst noch libapp miteinlinken:
gcc ... -lc -lm -lapp -L/usr/X11R6/lib -lX11

zini2001
09-04-2005, 12:59
was kann ich den noch anstelle von -lapp verwenden? einen relativen pfad z.B.? wie würde es lauten wenn sich die lib dateien nicht im standard verzeichnis befinden?

ist denn sonst alles io mit dem makefile?

hier ist noch mal ein makefile welches bei graphapp dabei ist welches aber auch nicht funzt, aus dem ich teile herrauskopiert habe.

# Makefile for App:

CC = /usr/bin/gcc
AR = /usr/bin/ar
RANLIB = /usr/bin/ranlib
LD = /usr/bin/ld
MAKE_STATIC_LIB = /usr/bin/ar rc
MAKE_DYNAMIC_LIB = /usr/bin/ld -shared -fPIC -Bdynamic -o
X11_LIB = /usr/X11/lib/libX11.so
X11_LIB_DIR = /usr/X11/lib
X11_INC_DIR = /usr/X11/include


# Makefile rules (Linux X11 version):

CFLAGS = -O2 -Wall -I. -Ix11 -Iutility -Igui -Ilibz -Ilibpng -Ilibjpeg -Ilibgif -I$(X11_INC_DIR)
RM = rm -f

XLIBS = -L$(X11_LIB_DIR) -lX11 -lc -lm

APP_OBJECTS = utility/apputil.o utility/clipline.o utility/compose.o \
utility/control.o utility/deleting.o utility/dispatch.o \
utility/drawimg.o utility/drawing.o utility/drawtext.o \
utility/image.o utility/imglist.o utility/fontutil.o \
utility/malloc.o utility/palette.o utility/point.o \
utility/rect.o utility/region.o utility/resource.o \
utility/rgb.o utility/str.o utility/strtable.o \
utility/utf8.o utility/utf8regx.o utility/winutil.o \
gui/button.o gui/checkbox.o gui/cursors.o \
gui/dialog.o gui/dropfld.o gui/droplist.o \
gui/field.o gui/imagebtn.o gui/imgcheck.o \
gui/imglabel.o gui/label.o gui/listbox.o \
gui/menu.o gui/passfld.o gui/radiobtn.o \
gui/scroll.o gui/tabbtn.o gui/textbox.o \
gui/textundo.o \
imgfmt/imgread.o imgfmt/imgwrite.o \
imgfmt/readgif.o imgfmt/writegif.o \
imgfmt/readh.o imgfmt/writeh.o \
imgfmt/readjpg.o \
imgfmt/readpng.o \
x11/bmap.o x11/bmapimg.o x11/clipbrd.o \
x11/clut.o x11/cursor.o x11/drawbmap.o \
x11/drawwin.o x11/event.o x11/folder.o \
x11/font.o x11/graphics.o x11/init.o \
x11/keys2ucs.o x11/timer.o x11/win.o

GIF_OBJECTS = libgif/gif.o

JPEG_OBJECTS = libjpeg/jcapimin.o libjpeg/jcapistd.o libjpeg/jccoefct.o \
libjpeg/jccolor.o libjpeg/jcdctmgr.o libjpeg/jchuff.o \
libjpeg/jcinit.o libjpeg/jcmainct.o libjpeg/jcmarker.o \
libjpeg/jcmaster.o libjpeg/jcomapi.o libjpeg/jcparam.o \
libjpeg/jcphuff.o libjpeg/jcprepct.o libjpeg/jcsample.o \
libjpeg/jctrans.o libjpeg/jdapimin.o libjpeg/jdapistd.o \
libjpeg/jdatadst.o libjpeg/jdatasrc.o libjpeg/jdcoefct.o \
libjpeg/jdcolor.o libjpeg/jddctmgr.o libjpeg/jdhuff.o \
libjpeg/jdinput.o libjpeg/jdmainct.o libjpeg/jdmarker.o \
libjpeg/jdmaster.o libjpeg/jdmerge.o libjpeg/jdphuff.o \
libjpeg/jdpostct.o libjpeg/jdsample.o libjpeg/jdtrans.o \
libjpeg/jerror.o libjpeg/jfdctflt.o libjpeg/jfdctfst.o \
libjpeg/jfdctint.o libjpeg/jidctflt.o libjpeg/jidctfst.o \
libjpeg/jidctint.o libjpeg/jidctred.o libjpeg/jmemmgr.o \
libjpeg/jmemnobs.o libjpeg/jquant1.o libjpeg/jquant2.o \
libjpeg/jutils.o

PNG_OBJECTS = libpng/png.o libpng/pngerror.o libpng/pngget.o \
libpng/pngmem.o libpng/pngpread.o libpng/pngread.o \
libpng/pngrio.o libpng/pngrtran.o libpng/pngrutil.o \
libpng/pngset.o libpng/pngtrans.o libpng/pngwio.o \
libpng/pngwrite.o libpng/pngwtran.o libpng/pngwutil.o

LIBZ_OBJECTS = libz/adler32.o libz/compress.o libz/crc32.o \
libz/deflate.o libz/infblock.o libz/infcodes.o \
libz/inffast.o libz/inflate.o libz/inftrees.o \
libz/infutil.o libz/trees.o libz/uncompr.o \
libz/zutil.o

OBJECTS = $(APP_OBJECTS) $(GIF_OBJECTS) $(JPEG_OBJECTS) \
$(PNG_OBJECTS) $(LIBZ_OBJECTS)

HEADERS = apptypes.h app.h x11/appint.h utility/apputils.h gui/appgui.h gui/cursors.h

LIB = libapp.a
DLL = libapp.so

static: $(LIB)

dynamic: $(DLL)

$(LIB): $(OBJECTS) $(HEADERS)
$(RM) $(LIB)
$(MAKE_STATIC_LIB) $(LIB) x11/*.o utility/*.o gui/*.o imgfmt/*.o libgif/*.o libjpeg/*.o libpng/*.o libz/*.o
$(RANLIB) $(LIB)

$(DLL): $(OBJECTS) $(HEADERS)
$(RM) $(DLL)
$(MAKE_DYNAMIC_LIB) $(DLL) x11/*.o utility/*.o gui/*.o imgfmt/*.o libgif/*.o libjpeg/*.o libpng/*.o libz/*.o $(XLIBS)

apptypes.h: apptypes.c
# Regenerating apptypes.h file
$(CC) $(CFLAGS) -o apptypes apptypes.c
./apptypes
$(RM) apptypes
# apptypes.h created

ga2: ga2.o $(LIB) $(DLL)
# Create GraphApp version 2 compatability library
$(RM) libga2.a
$(MAKE_STATIC_LIB) libga2.a x11/*.o utility/*.o gui/*.o imgfmt/*.o libgif/*.o libjpeg/*.o libpng/*.o libz/*.o ga2.o
$(RANLIB) libga2.a
$(RM) libga2.so
$(MAKE_DYNAMIC_LIB) libga2.so x11/*.o utility/*.o gui/*.o imgfmt/*.o libgif/*.o libjpeg/*.o libpng/*.o libz/*.o $(XLIBS) ga2.o

demo: static demo/imagine.o
$(CC) $(CFLAGS) -o demo/imagine demo/imagine.o $(LIB) $(XLIBS)

demo2: static demo/tester.o
$(CC) $(CFLAGS) -o demo/tester demo/tester.o $(LIB) $(XLIBS)

demo3: static demo/viewutf8.o
$(CC) $(CFLAGS) -o demo/viewutf8 demo/viewutf8.o $(LIB) $(XLIBS)

demo4: static demo/imgtest.o
$(CC) $(CFLAGS) -o demo/imgtest demo/imgtest.o $(LIB) $(XLIBS)

demo5: static demo/blend.o
$(CC) $(CFLAGS) -o demo/blend demo/blend.o $(LIB) $(XLIBS)

tidy:
$(RM) */*.o core

clean: tidy
$(RM) $(LIB) $(DLL)

ich seh den wald vor lauter bäumen nicht!!