2

I do not know much about make files. I am a student and this code was given to me and to modify c code itself. I only have a basic knowledge of make files.

I keep getting this error:

make[2]: Entering directory `/home/abdelrahman/Documents/Eclipse/storage/test/a1-partial'
make[2]: Leaving directory `/home/abdelrahman/Documents/Eclipse/storage/test/a1-partial'
cd a1-partial && make -s
expr: syntax error
make[2]: Entering directory `/home/abdelrahman/Documents/Eclipse/storage/test/a1-partial'
make[2]: Leaving directory `/home/abdelrahman/Documents/Eclipse/storage/test/a1-partial'
make[2]: *** No rule to make target `-lcheck', needed by `main'.  Stop.
make[1]: *** [builda1-partial] Error 2
make: *** [test] Error 2
make[1]: Leaving directory `/home/abdelrahman/Documents/Eclipse/storage/test'

this is my make file:

include ../Makefile.common

# Pick a random port between 5000 and 7000
RANDPORT := $(shell /bin/bash -c "expr \( $$RANDOM \% 2000 \) \+ 5000")

# The default target is to build the test.
build: main

# Build the test.
main: main.c $(SRCDIR)/$(CLIENTLIB) -lcheck -lcrypt
    $(CC) $(CFLAGS) -I $(SRCDIR) $^ -o $@ 

# Run the test.
run: init storage.h main
    for conf in `ls *.conf`; do sed -i -e "1,/server_port/s/server_port.*/server_port $(RANDPORT)/" "$$conf"; done
    env CK_VERBOSITY=verbose ./main $(RANDPORT)

# Make storage.h available in the current directory.
storage.h:
    ln -s $(SRCDIR)/storage.h

# Clean up
clean:
    -rm -rf main *.out *.serverout *.log ./storage.h ./$(SERVEREXEC)  

.PHONY: run
Joseph Quinsey
  • 9,553
  • 10
  • 54
  • 77
amoh
  • 163
  • 12

1 Answers1

3

A quick fix might be to change the lines:

main: main.c $(SRCDIR)/$(CLIENTLIB) -lcheck -lcrypt
    $(CC) $(CFLAGS) -I $(SRCDIR) $^ -o $@ 

to:

main: main.c $(SRCDIR)/$(CLIENTLIB) 
    $(CC) $(CFLAGS) -I $(SRCDIR) $^ -o $@ -lcheck -lcrypt

Explanation: As Mad Scientist points out, the GNU make can interpret -lcheck (etc.) as a prerequisite, but only if the library libcheck.a or libcheck.so is a target in the current makefile, or if is locatable in the standard places. Otherwise it just thinks it's a prerequisite named -lcheck, which it doesn't know how to build.

To get the standard places for library files, adding -Wl,--verbose in the $(CC) command line gives (on my system):

SEARCH_DIR("/usr/i386-redhat-linux/lib"); 
SEARCH_DIR("/usr/local/lib"); 
SEARCH_DIR("/lib"); 
SEARCH_DIR("/usr/lib");

See also How to print the ld(linker) search path.

Community
  • 1
  • 1
Joseph Quinsey
  • 9,553
  • 10
  • 54
  • 77
  • 1
    GNU make can interpret `-lcheck` (etc.) as a prerequisite, but _only_ if the library `libcheck.a` or `libcheck.so` is a target in the current makefile (or is locatable in the standard places). Otherwise it just thinks it's a prerequisite named `-lcheck`, which it doesn't know how to build. So, given the above makefile this answer is correct. – MadScientist Jan 29 '14 at 17:37
  • @MadScientist: Thanks. I have added your comment to my answer. – Joseph Quinsey Jan 29 '14 at 18:27