【发布时间】:2020-04-03 01:18:14
【问题描述】:
我正在处理来自 tensorflow 存储库的一个相当大的 Makefile,我需要添加一个文件链接。
在调试了一个链接错误之后,我发现如果我的文件以.cc结尾,那么链接错误就会消失,而当链接一个.c文件时,就会出现错误(文件内容保持不变)。
我在 Makefile.inc 文件中链接该文件:
.
.
.
FL_SRCS := \
tensorflow/lite/vis_mi/main.cc \
myFunctions.c \ -->>>>IF I CHANGE THE FILENAME TO myFunctions.cc and link to this .cc file here, it works!!
.
.
.
# Builds a standalone binary.
$(eval $(call vis_test,vis_mi,\
$(FL_SRCS),$(FL_HDRS)))
使用.c结尾时的链接错误:
tensorflow/lite/vis_mi/main.o: In function `main':
tensorflow/lite/vis_mi/main.cc:183: undefined reference to `printMsg()'
../downloads/gcc_embedded/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/bin/ld: link errors found, deleting executable `tensorflow/lite/vis_mi'
collect2: error: ld returned 1 exit status
gmake: *** [tensorflow/lite/vis_mi/Makefile.inc:578: tensorflow/lite/vis_mi/bin/micro_speech] Error 1
.c 文件代码:
#include <stdio.h>
#include "myFunctions.h"
void printMsg(){
//do something here
}
还有头文件:
#ifndef MYFUNCTIONS_H
#define MYFUNCTIONS_H
void printMsg();
#endif /* MYFUNCTIONS_H */
如何包含以 .c 结尾的文件? Makefile 对我来说相当新,并且不想包含所有详细信息,如果您需要 Makefile 中的任何更多详细信息来回答这个问题,我很乐意编辑我的帖子。
【问题讨论】:
-
文件扩展名告诉 make 是否将文件视为 C 代码或 C++ 代码。这会改变编译器、标志、使用的 make 变量等。gcc.gnu.org/onlinedocs/gcc/Overall-Options.html
-
那么,您的代码实际上是 C 还是 C++?如果是 C++,那么使用
.c扩展名是没有意义的,因为这只会让所有人感到困惑。 -
@kaylum 它的 C 代码
-
而包括库在内的整个应用程序都是C?如果是这种情况,那么我们将需要更多详细信息,包括实际错误、makefile 规则和变量等。我已经为您提供了更改扩展名所做的事情,但除了给定的信息之外,无法提供更多信息。
-
一个文件被编译为
C++(main.cc),另一个被编译为C(myFunctions.c)。如果不更改代码,那将无法工作。如果所有代码确实是 C,则将main.cc更改为main.c。
标签: c makefile gnu-make tensorflow-lite cc