【问题标题】:Undefined reference to log with make command使用 make 命令对日志的未定义引用
【发布时间】:2016-03-26 10:16:03
【问题描述】:

我是 Linux 操作系统的新手。我正在尝试运行从http://cbio.mskcc.org/leslielab/software/string_kernels.html 下载的代码 我使用 makefile 编译 ./profkernel 中的 ./src 文件。 但是,当我运行 make 时,出现以下错误: screenshot

makefile 看起来像这样

# MITRA MakeFile


ifeq ($(MODE),debug)
    #Debug flags
    COMPFLAGS =  -c -g -pg -Wall
    CC = cc
    CLIBS = -lm -g -pg
else 
    ifeq ($(MODE),memwatch)
    #Memwatch flags
    COMPFLAGS = -DMEMWATCH -DMW_STDIO -c -g -Wall -pg
    CC = cc
    CLIBS = -DMEMWATCH -DMW_STDIO -lm  -g -Wall -pg
else
    #Efficient Flags
    COMPFLAGS = -c -O3 
    CC = cc
    CLIBS = -lm  -O3
endif
endif

INCLUDES = HashTable.h mitra.h MiscUtil.h SymbolTable.h SymbolTable.h   Globals.h  Input.h



string-kernel   : string-kernel.o HashTable.o MiscUtil.o SymbolTable.o Globals.o  Input.o memwatch.o
${CC} ${CLIBS} -o  string-kernel string-kernel.o HashTable.o MiscUtil.o  SymbolTable.o Globals.o  Input.o memwatch.o

%.o : %.c
${CC} ${COMPFLAGS} $< -o $@

TAGS  :
     etags *.c *.h

clean :
     rm string-kernel *.o

我注意到有类似的问题。我试图从这些答案中添加相同的词,例如

LDFLAGS=-lm or LDLIBS=-lm

但它没有用。 有人知道吗?非常感谢

【问题讨论】:

  • 希望这个问题已经得到解答,只需添加CC=gcc CFLAGS=-Wall LDFLAGS=-lm 检查此stackoverflow.com/questions/13249610/…
  • 我试过这个,但它不起作用。也许是因为我们的代码不同。无论如何,谢谢

标签: linux makefile


【解决方案1】:

-l 选项(在这个 Makefile 中的 ${CLIBS} 中)应该在使用它们的目标文件之后,而不是之前。否则,当使用静态库时链接将失败,或者在这种情况下,当链接器默认启用 --as-needed 时(例如在 Ubuntu 中)。所以

${CC} -o  string-kernel string-kernel.o HashTable.o MiscUtil.o  SymbolTable.o Globals.o  Input.o memwatch.o ${CLIBS}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-29
    • 2012-02-27
    • 1970-01-01
    • 2011-02-13
    • 2013-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多