【发布时间】:2016-04-03 03:20:56
【问题描述】:
我正在尝试使用 um.c 从当前文件夹中编译一个名为 um 的程序 并包括一些外部实现。 .h 文件位于一个目录中,但实现这些 .h 文件的 .c 文件位于不同的目录中。下面是我的makefile。编译器似乎知道在哪里查找 .h 文件。但是,链接器失败并产生错误:
ld: symbol(s) not found for architecture x86_64
clang: fatal error: linker command failed with exit code 1
生成文件:
# define the C compiler to use
CC = gcc
# define any compile-time flags
CFLAGS = -g -O -Wall -Wextra -Werror -Wfatal-errors -std=c99 -pedantic
# define any directories containing header files other than /usr/include
INCLUDES = -I/Users/nguyenmanhduc/Documents/C\ library/cii/include
# define library paths in addition to /usr/lib
LFLAGS = -L/Users/nguyenmanhduc/Documents/C\ library/cii/src
# define any libraries to link into executable:
LIBS = -lm
# define the C source files
SRCS = um.c
# define the C object files
OBJS = $(SRCS:.c=.o)
# define the executable file
MAIN = um
.PHONY: depend clean
all: $(MAIN)
@echo Simple compiler named um has been compiled
$(MAIN): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
clean:
$(RM) *.o *~ $(MAIN)
depend: $(SRCS)
makedepend $(INCLUDES) $^
这个问题可能看起来很奇怪,因为我对 makefile 几乎没有经验,但是有没有办法可以使用 makefile 链接不同文件夹中的 .h 和 .c 文件。
谢谢!
【问题讨论】: