List Info

Thread: Make: puzzeling make behaviour ?




Make: puzzeling make behaviour ?
country flaguser name
United States
2007-02-18 16:37:46
Hi,

I am trying to compile a simple program that use a static
library in
~/lib with corresponding include file in ~/include. My
LD_LIBRARY_PATH
includes ~/lib. Here is the Makefile

------------------------------------------------------------
------
CC=gcc
GLLIB=-lGL
GLULIB=-lGLU
GUILIBS=-L/usr/X11R6/lib -lX11
OTHRLIBS=-lm
GLTKPATH=/home/bt
GLTKLIB=-L$(GLTKPATH)/lib -lgltk
GLTKINC=-I$(GLTKPATH)/include

CFLAGS=$(GLTKINC)
LDFLAGS=$(GUILIBS) $(GLLIB) $(GLULIB) $(OTHRLIBS)
$(GLTKLIB)

SRCFILES=$(wildcard *.c)
OBJFILES=$(patsubst %.c,%.o, $(SRCFILES))
PROGRAMS=$(patsubst %.c,%, $(SRCFILES))

build:  $(PROGRAMS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o "$" "$<"
	
clean:
	rm -f $(PROGRAMS)
------------------------------------------------------------
-------

However the compilation fails even though all the paths in
this makefile
are correct, gcc can not find symbols defined in libgltk.a .
Also
if I try to change the gcc command line and then run make
again it 
does not run the changed version of the command !!! I am
baffled.
For instance if I surround the LDFLAGS argument with -Wl,
--startgroup
and -Wl, --endgroup and run make, these don't appear in the
echoed
command line. Of for that matter if I change the order of
any of the 
gcc arguments, on executing make the changed order is not
reflected
in the echoed command line. In my working directory I only
have two
files : a c program and the Makefile. My make version is
3.80 and
gcc version is 3.3.5 and I am using Debian/Sarge. Using
vim's
"set list" feature I can ensure there are not
extraneous characters
in the make file and tabs/newlines are where they should
be.

Would be grateful for you suggestions.

regards
b thomas

_______________________________________________
help-gnu-utils mailing list
help-gnu-utilsgnu.org

http://lists.gnu.org/mailman/listinfo/help-gnu-utils

Re: Make: puzzeling make behaviour ?
country flaguser name
Sweden
2007-02-19 01:31:59
B Thomas <thomasbno.email.com> wrote:
> I am trying to compile a simple program that use a
static library in
> ~/lib with corresponding include file in ~/include. My
LD_LIBRARY_PATH
> includes ~/lib.

I don't think that gcc cares about LD_LIBRARY_PATH when it
searches for
static libs. LD_LIBRARY_PATH is used by ld.so to find
dynamics libs.

> Here is the Makefile 

> GLTKPATH=/home/bt
> GLTKLIB=-L$(GLTKPATH)/lib -lgltk
> GLTKINC=-I$(GLTKPATH)/include

So you have pointed out where to search for libraries and
header files,
you have also told gcc to search for a library named
libgltk.a.

> However the compilation fails even though all the paths
in this makefile
> are correct, gcc can not find symbols defined in
libgltk.a . 

Is libgltk.a really a static library? What does 

nm /home/bt/lib/libgltk.a

and

ar t /home/bt/lib/libgltk.a

give?

> Also if I try to change the gcc command line and then
run make again it 
> does not run the changed version of the command !!!

That is because it has never run your command. Instead make
has been using
a built in command in lack of any useful rule:

> SRCFILES=$(wildcard *.c)
> OBJFILES=$(patsubst %.c,%.o, $(SRCFILES))
> PROGRAMS=$(patsubst %.c,%, $(SRCFILES))

> build:  $(PROGRAMS)
> 	$(CC) $(CFLAGS) $(LDFLAGS) -o "$"
"$<"

Say that you have a single file called "myfile.c".
If so, above you have a
rule that expands to:

build: myfile
	$(CC) $(CFLAGS) $(LDFLAGS) -o build myfile

I don't think the above rule was what you intended. Instead
of using the
rule above make will do its best to find a way to build
"myfile" as that
is needed by "build". This could also explain your
problem with the static
library, are the flags to find the library used when gcc
tries to compile
your file?

regards Henrik
-- 
The address in the header is only to prevent spam. My real
address is:
hc1(at)poolhem.se Examples of addresses which go to
spammers:
rootlocalhost postmasterlocalhost

_______________________________________________
help-gnu-utils mailing list
help-gnu-utilsgnu.org

http://lists.gnu.org/mailman/listinfo/help-gnu-utils

Re: Make: puzzeling make behaviour ?
country flaguser name
United States
2007-02-19 22:19:26
Hi

I changed the build rule to 

build:  $(PROGRAMS)
 	$(CC) $(CFLAGS) $(LDFLAGS) -o "$<"
"$<".c

Shouldn't this work ? However I still have
the same problem.  This make file rule or something
else results in :
gcc -I/home/bt/include   -L/usr/X11R6/lib -lX11 -lGL -lGLU
-lm
-L/home/bt/lib -lgltk  Hello_World.c   -o Hello_World

Notice the order of the last two arguments.

Also gcc complains of missing symbols 
which are shown to be present by nm. These
are :

tkInitWindow 
tkQuit
tkExposeFunc
tkReshapeFunc
tkDisplayFunc
tkExec

Output of nm/ar  commands is as follows :

 nm /home/bt/lib/libgltk.a

--------------------------------------------
cursor.o:
00000000 B cursorNum
00000100 C cursors
00000000 T tkNewCursor
         U tkRGBMap
00000230 T tkSetCursor
         U w
         U wRoot
         U XCreatePixmapCursor
         U XCreatePixmapFromBitmapData
         U XDefineCursor
         U xDisplay

event.o:
         U deleteWindowAtom
00000008 B DisplayFunc
00000000 t DoNextEvent
00000004 C drawAllowFlag
         U exit
00000000 B ExposeFunc
0000001c B IdleFunc
0000000c B KeyDownFunc
00000000 D lastEventType
00000010 B MouseDownFunc
00000018 B MouseMoveFunc
00000014 B MouseUpFunc
00000004 B ReshapeFunc
000007b0 T tkDisplayFunc
00000720 T tkExec
00000790 T tkExposeFunc
00000800 T tkIdleFunc
000007c0 T tkKeyDownFunc
000007d0 T tkMouseDownFunc
000007f0 T tkMouseMoveFunc
000007e0 T tkMouseUpFunc
000007a0 T tkReshapeFunc
         U w
         U xDisplay
         U XEventsQueued
         U XLookupString
         U XNextEvent
         U XPeekEvent
         U XPending
         U XRefreshKeyboardMapping
         U XResizeWindow

font.o:
000ee100 D bitmapFont
000a5f80 D filledFont
         U glBegin
         U glBitmap
         U glCallLists
         U glEnd
         U glEndList
         U glListBase
         U glNewList
         U glPixelStorei
         U glPopAttrib
         U glPushAttrib
         U glTranslatef
         U glVertex2f
0005de00 D outlineFont
         U strlen
00000000 D strokeFont
00000420 T tkCreateBitmapFont
000002c0 T tkCreateFilledFont
00000160 T tkCreateOutlineFont
00000000 T tkCreateStrokeFont
000004e0 T tkDrawStr

getset.o:
         U calloc
         U fprintf
         U free
         U glXMakeCurrent
         U stderr
00000000 T tkGetColorMapSize
00000140 T tkGetContext
00000130 T tkGetDisplayMode
00000110 T tkGetDisplayModeID
00000100 T tkGetDisplayModePolicy
00000020 T tkGetMouseLoc
00000080 T tkGetSystem
         U tkInitDisplay
00000150 T tkSetFogRamp
000004b0 T tkSetGreyRamp
00000740 T tkSetOneColor
000008a0 T tkSetOverlayMap
00000a00 T tkSetRGBMap
00000c80 T tkSetWindowLevel
         U w
         U XAllocColorCells
         U xDisplay
         U XQueryPointer
         U xScreen
         U XStoreColor
         U XStoreColors
         U XSync

image.o:
00000040 t ConvertLong
00000000 t ConvertShort
         U fclose
         U fopen
         U fread
         U free
         U fseek
         U fwrite
         U malloc
         U perror
00000330 t RawImageClose
000004d0 t RawImageGetData
00000390 t RawImageGetRow
000000a0 t RawImageOpen
         U stderr
         U tkQuit
000005f0 T tkRGBImageLoad

shapes.o:
         U cos
00000060 d faces.1
00000120 d faces.3
000001e0 d faces.5
000002a0 d faces.7
         U glBegin
         U glEnd
         U glEndList
         U glNewList
         U glNormal3fv
         U glPopMatrix
         U glPushMatrix
         U glRotatef
         U glTranslatef
         U gluCylinder
         U gluNewQuadric
         U gluQuadricDrawStyle
         U gluQuadricNormals
         U gluSphere
         U glVertex3fv
00000000 d n.0
000000c0 d n.2
00000180 d n.4
00000240 d n.6
         U sin
00000630 T tkSolidBox
000015c0 T tkSolidCone
000002a0 T tkSolidCube
00001470 T tkSolidCylinder
00000070 T tkSolidSphere
00000de0 T tkSolidTorus
00000450 T tkWireBox
00001540 T tkWireCone
000000f0 T tkWireCube
000013b0 T tkWireCylinder
00000000 T tkWireSphere
00000810 T tkWireTorus

window.o:
00000040 D colorMaps
         U cursorNum
00000004 C deleteWindowAtom
         U DisplayFunc
         U drawAllowFlag
00000130 t ErrorHandler
         U exit
         U ExposeFunc
00000280 t FindBestMainVisual
00000420 t FindExactMainVisual
000007d0 t FindOverlayVisual
         U fwrite
00000810 t GetMainWindowType
         U glFinish
         U glFlush
         U glXChooseVisual
         U glXCreateContext
         U glXDestroyContext
         U glXGetConfig
         U glXIsDirect
         U glXMakeCurrent
         U glXQueryExtension
         U glXSwapBuffers
         U IdleFunc
         U KeyDownFunc
         U MouseDownFunc
         U MouseMoveFunc
         U MouseUpFunc
         U printf
         U puts
         U ReshapeFunc
         U stderr
00000000 T tkCloseWindow
00000a10 T tkInitDisplay
000001d0 T tkInitDisplayMode
000001f0 T tkInitDisplayModeID
000001e0 T tkInitDisplayModePolicy
00000250 T tkInitPosition
00000ae0 T tkInitWindow
00000fd0 T tkQuit
00000c40 D tkRGBMap
         U tkSetOverlayMap
         U tkSetRGBMap
00000ff0 T tkSwapBuffers
00000000 D w
000009b0 t WaitForMainWindow
000009e0 t WaitForOverlayWindow
00000008 B wRoot
         U XCloseDisplay
         U XCreateColormap
         U XCreateWindow
         U XDestroyWindow
00000000 B xDisplay
         U XFlush
         U XFree
         U XFreeColormap
         U XGetErrorText
         U XGetVisualInfo
         U XIfEvent
         U XInternAtom
         U XMapWindow
         U XOpenDisplay
00000004 B xScreen
         U XSetErrorHandler
         U XSetWMColormapWindows
         U XSetWMProperties
         U XSetWMProtocols
         U XStringListToTextProperty
--------------------------------------

ar t /home/bt/lib/libgltk.a

cursor.o
event.o
font.o
getset.o
image.o
shapes.o
window.o
--------------------------------------
regards
b thomas



_______________________________________________
help-gnu-utils mailing list
help-gnu-utilsgnu.org

http://lists.gnu.org/mailman/listinfo/help-gnu-utils

Re: Make: puzzeling make behaviour ?
country flaguser name
Sweden
2007-02-20 01:01:53
B Thomas <thomasbno.email.com> wrote:

> I changed the build rule to 
> 
> build:  $(PROGRAMS)
>  	$(CC) $(CFLAGS) $(LDFLAGS) -o "$<"
"$<".c
> 
> Shouldn't this work ? However I still have
> the same problem. 

The problem remains because make thinks like this:

1) It wants to create a file named "build". To
create the file "build" it
thinks it has a command line which you have specified.

2) Before it can create "build" it will have to
create $(PROGRAMS). There
is no rule that specifies how to create $(PROGRAMS) so it
uses a built in
rule.

> This make file rule or something else results in :
> gcc -I/home/bt/include   -L/usr/X11R6/lib -lX11 -lGL
-lGLU -lm
> -L/home/bt/lib -lgltk  Hello_World.c   -o Hello_World

So make has a built in rule on how to build a program from a
C source. If
you still want to call your target "build" the
right way to do this would
be something like:

build:  $(PROGRAMS)

%: %.c
	$(CC) $(CFLAGS) $(LDFLAGS) -o $ $<


Above "build" depends on $(PROGRAMS) and a custom
rule has been specified
how programs are built from C source. The fact that no file
named "build"
is created is no problem. This is how Makefiles are usually
written.
However, the de-facto standard for the default rule is
usually "all"
instead of "build", but you are free to call the
rule whatever you want.

> Output of nm/ar  commands is as follows :

Your output from nm and ar looks fine, once you get the
right command done
by make the library will probably be usable.

regards Henrik
-- 
The address in the header is only to prevent spam. My real
address is:
hc1(at)poolhem.se Examples of addresses which go to
spammers:
rootlocalhost postmasterlocalhost

_______________________________________________
help-gnu-utils mailing list
help-gnu-utilsgnu.org

http://lists.gnu.org/mailman/listinfo/help-gnu-utils

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )