Q:

makefile linking issue

I have a trivial problem.. I am trying to modify a working Makefile to link a function I decided to add in my code simpletrial.cpp (The function is IniFile.cpp)
My old working Makefile is:
include Makefile.arch
TESTS           := simpletrial.cpp
TESTO           := $(TESTS:.C=.o)
TEST            := simpletrial

OBJ             = $(TESTO)
PROGRAMS        = $(TEST)

CXXFLAGS      += 
CXXFLAGS      += 
GLIBS         += 

.SUFFIXES: .$(SrcSuf) .$(ObjSuf) .$(DllSuf)

all:            $(PROGRAMS)

$(TEST):        $(TESTO)
        $(LD) $(LDFLAGS) $^ $(GLIBS) $(OutPutOpt)$@
        @echo "$@ done"

clean:
        @rm -f $(OBJ) $(TESTO) core *~ src/*~ include/*~

.$(SrcSuf).$(ObjSuf):
        $(CXX) $(CXXFLAGS) -c $< -o $@

I have tried without success to compile and link IniFile.cpp but I always receive the error "undefined reference to 'IniFile:: etc etc
thanks!

A:

Your link line is the following:
$(LD) $(LDFLAGS) $^ $(GLIBS) $(OutPutOpt)$@

Here you link with $^ which is all of the pre-reqs for the rule, which in this case is $(TESTO) and that is simpletrial.o, you don't appear to have IniFile.cpp in there, so it won't link with it. To fix it just add IniFile.cpp to your TESTS as follows:
TESTS           := simpletrial.cpp InFile.cpp

Then it should compile and link both files together and produce simpletrial as a result.
Additionally I think that your TESTO line might need to change as well:
TESTO           := $(TESTS:.cpp=.o)

That should take the values in the $(TESTS) variable and change the suffix from .cpp to .o, the current definition will only change .C to .o... 

