$ sudo apt install libunittest++-dev
After that
$ sudo find / -iname "*UnitTest++.*" 2> /dev/null
/usr/include/UnitTest++/UnitTest++.h
/usr/lib/x86_64-linux-gnu/pkgconfig/UnitTest++.pc
/usr/lib/x86_64-linux-gnu/libUnitTest++.so
/usr/lib/x86_64-linux-gnu/libUnitTest++.so.2
/usr/lib/x86_64-linux-gnu/libUnitTest++.so.2.0.0
But there's no libUnitTest++.a
as I have in Windows where I compiled UnitTest++ myself according the instructions here. Also I don't see the source code files.
Can I use this installation for my testing or need to download the sources and compile them myself? Or how can I use libUnitTest++.so
instead of libUnitTest++.a
?
Here is one of my tests:
#include "UnitTest++/UnitTest++.h"
#include "skip_list.cpp"
#include <iostream>
using namespace std;
TEST(NodeTest)
{
SkipListNode<int> node(15, 2);
CHECK_EQUAL(15, node.key);
CHECK_EQUAL(2, node.height);
CHECK(!node.next[0]);
CHECK(!node.next[1]);
CHECK(!node.next[2]);
}
int main(int, const char *[])
{
return UnitTest::RunAllTests();
}
Now it says:
g++ -std=c++11 -Wall -g skip_list_test.cpp
/tmp/cc2zCui4.o: In function `TestNodeTest::RunImpl() const':
/home/greg/study/data_structures/02_03_01_skip_list/skip_list_test.cpp:16: undefined reference to `UnitTest::CurrentTest::Details()'
Just as you did in your answer, you need to tell
g++
to include the library. There, you provide it with the full path to thelibUnitTest++.a
archive file that you compiled yourself as an input.To use the library installed by your system package manager -- in this case,
apt
-- it would be more common to provide a linker directive. In this case,-l UnitTest++
instructs the linker to "search my system library paths forlibUnitTest++.so
"