-1

我的设置是这样的:

src/
  dir1/
    header.h
    dir11
      (several files, every including header.h)
  dir2/
  (and so on)

但链接器告诉我undefined reference to (the function which is defined in the subdir "dir11")。标题如下所示:

#ifndef header_h
#define header_h

/* some includes, all protected via ifndef-define-endif */

/* function prototypes for all functions in the 'dir11' subdir */
#endif // header_h

生成文件:

# some variables are defined before...

TARGET=mytarget 
SOURCES= ${shell find ${SRC} -type f -name '*.c'} 
OBJECTS=${foreach x, $(basename $(SOURCES)), $(x).o}

compile: ${OBJECTS}

%.o: %.c 
        ${CC} -c ${CFLAGS} ${HEADERS} $^ -o $@

link:
        ${LD} ${OBJECTS} -o ${TARGET}

如何解决这个问题?为子目录中的每个文件编写标题是我想要去的最后一种方式,因为其中有大约 50 个文件!

编辑:也许这很有用:header.h 也包括在内,以调用函数!我是否必须extern在包含 elsewere 时声明此功能?

4

1 回答 1

0

您所有的包含保护定义是否不同?如果不是,您将收到未定义的参考警告/错误,具体取决于您的编译器设置

于 2013-01-29T22:24:15.600 回答