我使用带有 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/