packagers note: do not run ld directly

Tomas Janousek tjanouse at redhat.com
Thu Aug 9 12:12:56 UTC 2007


Hi,

> e.g. a makefile line:
> 
> 	$(LD) -shared -o $@ $(objs)
> 
> should be:	
> 
> 	$(CC) -shared -o $@ $(objs)
> 
> Best practice is to use consistently the flags otherwise passed to
> the compiler, and also use LDFLAGS, i.e.:
> 
> 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $(objs)

Are you sure CFLAGS should be used?

The default GNU make rules don't do so:

LINK.o = $(CC) $(LDFLAGS) $(TARGET_ARCH)
%: %.o
        $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@


Just for inspiration, I use the following rules in my Makefiles:

%.so.$(SOMAJOR).$(SOMINOR): CFLAGS += -fPIC
%.so.$(SOMAJOR).$(SOMINOR): LDFLAGS += -shared \
        -Wl,-soname,$(patsubst %.so.$(SOMAJOR).$(SOMINOR),%.so.$(SOMAJOR),$@)
%.so.$(SOMAJOR).$(SOMINOR): %.o
        $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@

Regards,
-- 
TJ. (Brno, CZ), BaseOS, Red Hat




More information about the fedora-devel-list mailing list