CUnit : undefined reference to `CU_assertImplementation'
使用cc -o test testtest.c -lcunit对其进行了编译,但仍无法正确运行测试。他们由于某种原因崩溃:)
我正在从事一个项目,最近我说服自己应该继续采用测试驱动的方法。主要是因为项目本身正在增长,我想证明所有功能都能正常工作。
但是我在做cunit教程时遇到了一些问题。
http://cunit.sourceforge.net/doc/writing_tests.html
这是我的cunit测试文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <CUnit/CUnit.h> main(){ test_maxi(); } int maxi(int i1, int i2){ return (i1 > i2) ? i1 : i2; } void test_maxi(void){ CU_ASSERT(maxi(0,2) == 2); CU_ASSERT(maxi(0,-2) == 0); CU_ASSERT(maxi(2,2) == 2); } |
当我尝试编译它们时出现这些错误:
testtest.c:(.text+0x62): undefined reference to
CU_assertImplementation' testtest.c:(.text+0x9b): undefined reference CU_assertImplementation' testtest.c:(.text+0xd5): undefined
to
reference to `CU_assertImplementation' collect2: ld returned 1 exit
status
我用过google,我认为它与链接有关吗?但是我没有得到很多帮助。
最佳问候
里卡德
OP的解决方案。
使用以下命令对其进行编译:
1 | gcc -Wall -o test basicexample.c -lcunit |