使用makefiles c编译函数的未定义引用
我正在尝试使用名为 coco.c
的文件中的一组函数来运行一些实验(来自 coco 优化平台,可以在 https://github.com/numbbo/coco)。该文件还附带一个头文件coco.h
。我一直在尝试通过编写我自己的名为 testing.c
的文件来测试 coco.c
文件中的调用函数是否有效。
完整的testing.c 文件如下所示,
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "coco.h"
#define max(a,b) ((a) > (b) ? (a) : (b))
int main(void){
coco_suite_t *suite;
suite = coco_suite("bbob-biobj", "", "");
return 0;
}
我已将 coco.h
和 coco.c
放在与 testing.c
相同的文件夹中> 以及我的 Makefile.in
。 coco_suite
是coco.c
中的一个函数。
我一直在使用的 makefile 如下所示(其中大部分是我从示例 makefile 中复制的)。
## Makefile
LDFLAGS += -lm
CCFLAGS ?= -g -ggdb --std+c89 -pedantic -Wall -Wextra -Wstrict-prototypes -Wshadow -Wno-sign-compare -Wconversion
all: testing
clean:
rm -f coco.o
rm -f testing.o testing
testing: testing.o coco.o
gcc ${CCFLAGS} -o testing coco.o testing.o ${LDFLAGS}
coco.o: coco.h coco.c
gcc -c ${CCFLAGS} -o coco.o coco.c
testing.o: coco.h coco.c testing.c
gcc -c ${CCFLAGS} -o testing.o testing.c
但是,当尝试构建可执行文件时,我收到一条错误消息,指出未定义对 coco_suite
的引用。我知道函数原型位于头文件中,完整代码位于源文件中,因为我已经成功运行了 coco 平台作者提供的示例。我已经仔细检查了空格(制表符与空格等),它与提供的工作示例完全匹配。然而,即使我将示例代码复制并粘贴到 testing.c
文件中,我也会遇到相同的错误。
这让我相信问题出在 makefile 中,但我看不到它是什么。
有谁知道问题可能是什么?
I am trying to run some experiments using a set of functions inside a file called coco.c
(from the coco optimisation platform which can be found at https://github.com/numbbo/coco). This file also comes with a header file coco.h
. I have been trying to test if the calling functions from the coco.c
file works by writing my own file called testing.c
.
The full testing.c file can be seen below
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "coco.h"
#define max(a,b) ((a) > (b) ? (a) : (b))
int main(void){
coco_suite_t *suite;
suite = coco_suite("bbob-biobj", "", "");
return 0;
}
I have placed placed both coco.h
and coco.c
in the same folder as testing.c
along with my Makefile.in
. coco_suite
is a function inside coco.c
.
The makefile that I have been using can be seen below (most of which I have copied from the example makefile).
## Makefile
LDFLAGS += -lm
CCFLAGS ?= -g -ggdb --std+c89 -pedantic -Wall -Wextra -Wstrict-prototypes -Wshadow -Wno-sign-compare -Wconversion
all: testing
clean:
rm -f coco.o
rm -f testing.o testing
testing: testing.o coco.o
gcc ${CCFLAGS} -o testing coco.o testing.o ${LDFLAGS}
coco.o: coco.h coco.c
gcc -c ${CCFLAGS} -o coco.o coco.c
testing.o: coco.h coco.c testing.c
gcc -c ${CCFLAGS} -o testing.o testing.c
However, when attempting to build the executable I get an error saying undefined reference to coco_suite
. I know that the function prototype is in the header file and the full code is in the source file as I have successfully run the example provided by the authors of the coco platform. I have doublechecked the whitespace (tabs vs spaces etc) and it matches exactly with the working example provided. However even when I copy and paste the example code into the testing.c
file I get the same error.
This leads me to believe that the issue is in the makefile but I cant see what it is.
Does anyone know what the issue could be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论