使用 apt-get 安装时 Boost 测试编译错误

Boost Testing compilation error when installed with apt-get

我刚刚安装了 Boost usig sudo apt-get。之后,我编写了以下代码来测试我在“first_n_follow.h”

中声明的函数之一
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>

#include "first_n_follow.h"
#define BOOST_TEST_MODULE MyTest
#include <boost/test/unit_test.hpp>

using namespace std;

BOOST_AUTO_TEST_CASE( my_test )
{
    set<char> sample = {'b','c','d'};
    map<char, set<char>> sample_map;
    sample_map['a'] = sample;
    BOOST_TEST(print_map(sample_map)==0);
}

遗憾的是,当我使用以下命令编译上述文件first_n_follow_test.cpp时:

g++ -o test.o first_n_follow_test.cpp 

我收到以下错误:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
/usr/bin/ld: /tmp/ccefJDJt.o: in function `my_test_invoker()':
first_n_follow_test.cpp:(.text+0x100): undefined reference to `boost::unit_test::unit_test_log_t::set_checkpoint(boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::basic_cstring<char const>)'

后跟很长的堆栈跟踪。关于问题可能是什么,有什么想法吗?

即使我替换对我的代码的调用并编写 BOOST_TEST(0==0);, 它显示相同的错误。 非常感谢任何帮助。

缺少boost单元测试框架库的链接

g++ -o test.o first_n_follow_test.cpp -lboost_unit_test_framework

未定义的引用错误通常意味着在链接阶段缺少库或目标文件