Where to add the -lm flag within a makefile?

Andarin

I am trying to compile a simulation program called COSI: http://www.broadinstitute.org/~sfs/cosi/cosi_1.2.1.tar

After unzipping it with tar xfp cosi_package.tar, I try to run make as stated in the README within the newly created directory cosi_1.2. Unfortunately, I get a lot of errors such as

coalescent.a(historical.o): In function `historical_process_pop_event':
historical.c:(.text+0x5c7): undefined reference to `log'
coalescent.a(historical.o): In function `historical_next_exp':
historical.c:(.text+0x76a): undefined reference to `exp'
../cosi_rand/random.a(ranbinom.o):ranbinom.c:(.text+0x702): more undefined references to `log' follow
collect2: ld returned 1 exit status
make[1]: *** [coalescent] Error 1
make[1]: Leaving directory `/home/myname/Desktop/cosi_1.2/cosi'
make: *** [all] Error 2

The MAKEFILE in the problematic sub-directory looks like this:

PACKAGE := coalescent
BINFILES := coalescent.c
SKIPFILES := 
ARFILE := $(PACKAGE).a
BINS := $(BINFILES:.c=)
PREFILES := $(wildcard *.c)
CFILES := $(filter-out $(SKIPFILES),$(PREFILES))
LIBFILES := $(filter-out $(BINFILES),$(CFILES))
OFILES := $(LIBFILES:.c=.o)
DFILES := $(CFILES:.c=.d)
FOO := $(ARFILE)(
BAR := )
AFILES := $(addprefix $(FOO), $(OFILES))
AFILES := $(addsuffix $(BAR), $(AFILES))
CC := gcc
CFLAGS := $(DEBUG) -O3 -Wall -ansi

all : $(BINS)
#   rm *.d; rm *.o
install : $(BINS)
    rm *.d; rm *.o
.PHONY : cleaninstall
cleaninstall : 
    rm $(BINS)

$(ARFILE) : $(AFILES)
    $(AR) cr $(ARFILE) $(?:.c=.o)
    $(RM) $(?:.c=.o)

$(BINS) : % : %.o $(ARFILE)
    ranlib $(ARFILE)
    $(CC) $(CFLAGS) -lm -v -o $@ [email protected] $(ARFILE) ../cosi_rand/random.a


%.d: %.c
    @$(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $< \
                      | sed '\''s/\($*\)\.o[ :]*/coalescent.a(\1.o) $@ : /g'\'' > $@; \
                      [ -s $@ ] || rm -f $@'

-include $(DFILES)

Obviously, all the errors are missing mathematical functions. Hence I tried adding -lm to CFLAGS but it didn't help. Any suggestions what I could do?

Fred Foo

-lm is a linker flag. It should appear at the end of the linker command:

$(CC) -v -o $@ [email protected] $(ARFILE) ../cosi_rand/random.a -lm

Apparently some compilers permit -l to appear anywhere. I still haven't found out which ones do, but my GCC wants them at the end, and in reverse order of dependency: if random.a needs libm, then libm should be linked in after random.a.

I also removed $(CFLAGS) from the linker command because you should pass linker options, not compiler options, when linking.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Makefile add last flag

From Dev

lm() called within mutate()

From Dev

-lm doesn't work for my Makefile

From Dev

Hard linking within makefile

From Dev

Hard linking within makefile

From Dev

How to add a aggregate function where selected columns are within the same query

From Dev

PHP - add new WHERE clause to SQL statement within foreach loop

From Dev

Add a flag to bash script

From Dev

Add Header Flag in YiiMailer

From Dev

Makefile: how to detect changes within the makefile itself?

From Dev

Passing Argument to lm in R within Function

From Dev

Passing Argument to lm in R within Function

From Dev

Using lm() within lapply with ifelse condition

From Dev

Makefile not prompting compiler to use optimization flag

From Dev

Git commit from within a Makefile

From Dev

R - Where is the `qr.lm` function

From Dev

Makefile - Add objects to folder

From Dev

Makefile - Add objects to folder

From Dev

add library on makefile

From Dev

Flag dates occurring after an event within individuals

From Dev

Clear the Backstack within an activity without using FLAG

From Dev

Using a flag number within unsigned integers

From Dev

Add flag to each item in list

From Dev

Add /MT compile flag to project

From Dev

Add flag to existing terminal command

From Dev

Linq statement Where within a Where

From Dev

Where are words stored when using the "Add word to dictionary" feature within a text editor?

From Dev

Laravel - How to add where statement within related table and parent table at the same time?

From Dev

Where is generate makefile menu option?