未定义引用'main'没有读取源文件

时间:2015-04-23 13:56:45

标签: c gcc makefile

当我尝试在笔记本电脑上编译代码时,我遇到了一个奇怪的问题。 它给了我这个错误:undefined reference to 'main'因为显然它看不到我的源文件,然后是对象。

但是,相同的makefile和代码在我的办公室机器上完美运行。

这是makefile。任何提示?

非常感谢你提前帮助我

ROOT = $(addprefix $(PWD), /)
BUILDS_DIR = $(addprefix $(ROOT), builds/)
SRCS_DIR   = $(addprefix $(ROOT), src/)
INCS_DIR   = $(addprefix $(ROOT), src/)
OBJS_DIR   = $(addprefix $(SRCS_DIR), objects/)
LIBS_DIR   = ./

SRCS = $(wildcard $(SRCS_DIR)*.c)
OBJS = $(SRCS:$(SRCS_DIR)%.c=$(OBJS_DIR)%.o)

TARGET = INTERP

EXES = $(addprefix $(BUILDS_DIR), $(TARGET))

CC       = gcc
CFLAGS   = -Wall -O3 -MD -DTRILIBRARY
INCLUDES = -I$(INCS_DIR)
CL       = gcc
LFLAGS   = 
LIBS     = -L$(LIBS_DIR) -lm
RM       = rm -f

.PHONY: all $(TARGET) distclean clean

default: clean $(TARGET)

$(TARGET): $(OBJS)
    @echo -e "\n\n\t\t*** Compiled $(TARGET) successfully! ***\n" ;
    $(CL) $(LFLAGS) -o $(BUILDS_DIR)$@ \
        $(OBJS) \
        $(LIBS)
    @echo -e "\n\n\t\t*** Linking $(TARGET) completed! ***\n"

$(OBJS): $(OBJS_DIR)%.o : $(SRCS_DIR)%.c
    $(CC) $(CFLAGS) $(INCLUDES) \
        -c $<\
        -o $@

distclean: clean
    $(RM) $(EXES)
    @echo -e "\n\n\t\t*** Purge $(TARGET) completed! ***\n"

clean:
    $(RM) $(OBJS_DIR)*.o \
        $(SRCS_DIR)*~
    @echo -e "\n\n\t\t*** Cleanup $(TARGET) completed! ***\n"

depend: $(SRCS)
    makedepend $(INCLUDES) $^

0 个答案:

没有答案