This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

linking C and C++ object files / libraries


Hi all,

I have been trying to link C and C++ .o files together, with always the same
errors (undefined reference to ...). So far, my solution was to use g++ for
all. But that was just delaying the inevitable, since now I am facing the
matter of a C library which shows exactly the same symptoms. Can you help?

Thanks,
Guilhem.

---
The Makefile is:

#
# Targets
#
ALL_TARGETS	= level detect fft


#
# Get things started.
#
.PHONY : help
help :
	@echo "Please type one of the following:"
	@echo "  'make all'            (currently, <`echo $(ALL_TARGETS) | sed 's/ />
</'`>)"
	@echo "  'make [target]'"
	@echo "  'make clean_all'"
	@echo "  'make clean_[target]'"

#
# Dependencies
#
level_objs	= level.o audiofile.o g711.o opt_args.o tools.o
level_dep : $(level_objs)

detect_objs	= detect.o audiofile.o g711.o opt_args.o tools.o
detect_dep : $(detect_objs)

fft_objs	= fft.o audiofile.o opt_args.o
fft_dep : $(fft_objs)
fft_LDFLAGS	= -L/usr/local/lib -lrfftw


#
# Configuration
#
CC		= g++
CPP		= g++
CFLAGS		= -Wall -O2
CPPFLAGS	= $(CFLAGS)
LD		= ld
LDFLAGS		= 


#
# Common rules
#
%.o : %.c
	$(CC) $(CFLAGS) -c -o $@ $<

%.o : %.cpp
	$(CPP) $(CPPFLAGS) -c -o $@ $<


#
# Rule to compile a set of .o files into one completely linked .o file
#
$(ALL_TARGETS) : % : %_dep
	rm -f $@
	$(LD) $(LFLAGS) $($@_LDFLAGS) $($@_objs) -o $@


.PHONY : all
all : $(ALL_TARGETS)

.PHONY : clean_%
clean_% :
	rm -f $($*_objs)

.PHONY : clean_all
clean_all : $(patsubst %,clean_%,$(ALL_TARGETS))
	rm -f core $(ALL_TARGETS)


__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://careers.yahoo.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]