c - 已安装检查 c 但未找到 "check.h"

标签 c windows ubuntu makefile windows-subsystem-for-linux

我使用带有 wsl ubuntu 18.04 的 windows 10 我试图从这里运行代码:
https://www.ccs.neu.edu/home/skotthe/classes/cs5600/fall/2015/labs/intro-check-lab-code.tgz
我安装了 gcc、makefile 并 checkin 了 ubuntu 终端。但是当我去$ make它说:

gcc money.o check_money.o -lcheck -lm -lpthread -lrt  -lgcov -coverage -o check_money_tests
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcheck.a(check_log.o): In function `subunit_lfun':
(.text+0x5f4): undefined reference to `subunit_test_start'
(.text+0x6bf): undefined reference to `subunit_test_fail'
(.text+0x6d4): undefined reference to `subunit_test_pass'
(.text+0x6ef): undefined reference to `subunit_test_error'
collect2: error: ld returned 1 exit status
Makefile:23: recipe for target 'check_money_tests' failed
make: *** [check_money_tests] Error 1
所以我打开 check_money.c 它说 check.h找不到。我在这里错过了什么?

最佳答案

简单版:您还应该链接 -lsubunit标志,即:

TST_LIBS = -lcheck -lm -lpthread -lrt -lsubunit
更好的是,所有的标志都应该取自 check的包配置,因为要求取决于 check图书馆已经建成(这就是 pkg-config 的发明目的)。因此,您可以改进您的Makefile,而不是硬编码您的选项。像这样:
CFLAGS = -c -Wall $(shell pkg-config --cflags check)
TST_LIBS = $(shell pkg-config --libs check)
结果:
$ make
gcc -c -Wall -pthread -fprofile-arcs -ftest-coverage src/*.c
gcc -c -Wall -pthread -fprofile-arcs -ftest-coverage  tests/*.c
gcc money.o check_money.o -lcheck_pic -pthread -lrt -lm -lsubunit -lgcov -coverage -o check_money_tests
...

关于c - 已安装检查 c 但未找到 "check.h",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63697460/

相关文章:

c++ - 仅 header 链接

c - sizeof (""+0) != sizeof(char *) 错误或未定义的行为?

php - 如何在 Windows 下的 PHP 中获取*任意*(即不是当前)用户的主目录?

ubuntu - 找不到包 tsodbc

c - "expression must have integral type"C中的开关问题

c - vSphere API 和自动化虚拟机管理

c - 如何在进度条中显示文本?

windows - SVN 校验和不匹配的根本原因是什么?

java - 在ubuntu中重新启动java应用程序

ubuntu - cron.d 中的 Cron 无法在 Docker 容器内运行的 Ubuntu 上运行