CUnit 安装笔记

今天安装 CUnit,发现几个坑,在此记一下。

首先下载 CUnit: http://cunit.sourceforge.net/

安装过程:

tar jxvf CUnit-2.1-3.tar.bz2
cd CUnit-2.1-3
./bootstrap
./configure
make
make install



这个时候,CUnit 已经安装好。但在使用的时候可能会有问题,在编译测试用例的时候,可能会出现:

cc -o tests/build-tests tests/httptest.c
/tmp/ccl6l4rB.o: In function `test1':
httptest.c:(.text+0x3b): undefined reference to `CU_assertImplementation'
/tmp/ccl6l4rB.o: In function `test2':
httptest.c:(.text+0x66): undefined reference to `CU_assertImplementation'
/tmp/ccl6l4rB.o: In function `main':
httptest.c:(.text+0x7d): undefined reference to `CU_initialize_registry'
httptest.c:(.text+0x86): undefined reference to `CU_get_error'
httptest.c:(.text+0x9f): undefined reference to `CU_add_suite'
httptest.c:(.text+0xaf): undefined reference to `CU_cleanup_registry'
httptest.c:(.text+0xb4): undefined reference to `CU_get_error'
httptest.c:(.text+0xcc): undefined reference to `CU_add_test'
httptest.c:(.text+0xe7): undefined reference to `CU_add_test'
httptest.c:(.text+0xf1): undefined reference to `CU_cleanup_registry'
httptest.c:(.text+0xf6): undefined reference to `CU_get_error'
httptest.c:(.text+0x102): undefined reference to `CU_basic_set_mode'
httptest.c:(.text+0x107): undefined reference to `CU_basic_run_tests'
httptest.c:(.text+0x10c): undefined reference to `CU_cleanup_registry'
httptest.c:(.text+0x111): undefined reference to `CU_get_error'
collect2: ld returned 1 exit status
make: *** [build-tests] Error 1



在编译的时候加 -lcunit 就可以了,例如我的makefile: 

build-tests : tests/httptest.o
	cc -o tests/build-tests tests/httptest.c -lcunit
tests/httptest.o : tests/httptest.c

test : build-tests
	tests/build-tests



如果在运行测试用例的时候出现:

./build-tests: error while loading shared libraries: libcunit.so.1: cannot open shared ob



提示找不到 libcunit.so.1,给它一个软连接即可:

sudo ln -s /usr/local/lib/libcunit.so.1 libcunit.so.1



搞定!


你可能感兴趣的:(CUnit 安装笔记)