Ian Collins wrote:
>
It does if you follow all the points. The first two are often overlooked.
Here is my Makefile
>
How are you building your executable?
Here is my Makefile
-----------------------------------------
OS = OS_LINUX
CC = gcc
CXX = g++
AR = ar
INCMYLIB = mylib.h
INC = $(INCMYLIB)
OBJMYLIB = mylib.o
OBJ = $(OBJMYLIB)
ROOTINCL = $(ROOTSYS)/include
MYLIB = mylib.a
CFLAGS = -g -D$(OS) -Wall -O2 -fno-strict-aliasing \
-I/usr/X11R6/include/ -I/usr/X11R6/include/X11
-I$(ROOTINCL) \
BOOLFLAG = -D_BOOL
ROOTFLAG = `root-config --libs`
CCFLAG = $(BOOLFLAG) $(ROOTFLAG)
LDFLAGS = -L/usr/X11R6/lib -z muldefs
LOADMYLIBES = $(MYLIB) -lm -lX11 -Xlinker -Bstatic -lforms -Xlinker
-Bdynamic
INT = main
EXT =
EXE = $(EXT) $(INT)
#------------------------------------------------------------------------------
all: $(OBJ) $(MYLIB) $(EXE)
#------------------------------------------------------------------------------
%.o: %.c $(INC)
$(CC) -c -o $*.o $*.c $(CFLAGS)
%.o: %.cc $(INC)
$(CXX) -c -o $*.o $*.cc $(CFLAGS) $(BOOLFLAG)
$(MYLIB): $(OBJ)
$(AR) cru $(MYLIB) $(OBJ)
%: %.c $(MYLIB)
$(CC) -o $* $*.c $(CFLAGS) $(LDFLAGS) $(LOADMYLIBES)
%: %.cc $(MYLIB)
$(CXX) -o $* $*.cc $(CFLAGS) $(CCFLAG) $(LDFLAGS) $(LOADMYLIBES)
#------------------------------------------------------------------------------
export:
cp -p -f $(EXT) /usr/local/bin
#------------------------------------------------------------------------------
clean:
rm -f *~ *.bak *.o $(EXE) core
#============== =============== =============== =============== =============== ====
This Makefile is used to compile several programs and be able to use
somebody else library, here I reduced it to the minimum only to study
this case.
Thanks,
Al