【问题标题】:make[2]: *** No rule to make target `-lcheck', needed by `main'. Stopmake[2]: *** 没有规则来制作目标 `-lcheck',`main' 需要。停止
【发布时间】:2014-02-21 16:09:18
【问题描述】:

我对制作文件知之甚少。我是一名学生,这个代码是给我的,用来修改 c 代码本身。我只有基本的make文件知识。

我不断收到此错误:

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'

这是我的制作文件:

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

【问题讨论】:

    标签: c makefile


    【解决方案1】:

    一个快速的解决办法可能是改变行:

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

    到:

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

    解释:正如 Mad Scientist 指出的那样,GNU make 可以将 -lcheck(等)解释为先决条件,但如果库 @987654326 @ 或 libcheck.so 是当前 makefile 中的目标,或者如果可以在标准位置定位。否则它只是认为这是一个名为-lcheck 的先决条件,它不知道如何构建它。

    要获得库文件的标准位置,在$(CC) 命令行中添加-Wl,--verbose 给出(在我的系统上):

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

    另见How to print the ld(linker) search path

    【讨论】:

    • GNU make 可以将-lcheck(等)解释为先决条件,但只有如果库libcheck.alibcheck.so 是当前makefile 中的目标(或位于标准位置)。否则它只是认为这是一个名为-lcheck 的先决条件,它不知道如何构建它。所以,鉴于上面的 makefile 这个答案是正确的。
    • @MadScientist:谢谢。我已将您的评论添加到我的答案中。
    猜你喜欢
    • 1970-01-01
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-14
    相关资源
    最近更新 更多