如何在Mac上动态链接cppunit?

时间:2018-05-15 17:39:42

标签: c++ macos linker g++

我使用此命令安装了GNU g ++和cppunit:

brew install gcc cppunit

库似乎已正确安装:

$ find / -name "libcppunit*" 2> /dev/null
/usr/local/lib/libcppunit-1.14.0.dylib
/usr/local/lib/libcppunit.a
/usr/local/lib/libcppunit.dylib
/usr/local/Cellar/cppunit/1.14.0/lib/libcppunit-1.14.0.dylib
/usr/local/Cellar/cppunit/1.14.0/lib/libcppunit.a
/usr/local/Cellar/cppunit/1.14.0/lib/libcppunit.dylib

这是我编写的一个使用cppunit的代码。该文件名为test.cpp。忽略此代码中没有测试运行器的事实。我现在只关心链接。

#include <cppunit/extensions/HelperMacros.h>
#include <iostream>

class FooTest : public CppUnit::TestFixture
{
protected:
    void testBasic()
    {
        CPPUNIT_ASSERT_EQUAL(1 + 1, 2);
    }

    void testBasic2()
    {
        CPPUNIT_ASSERT_EQUAL(1 + 2, 3);
    }
private:
    CPPUNIT_TEST_SUITE(FooTest);
    CPPUNIT_TEST(testBasic);
    CPPUNIT_TEST(testBasic2);
    CPPUNIT_TEST_SUITE_END();
};

CPPUNIT_TEST_SUITE_REGISTRATION(FooTest);

int main()
{
    std::cout << "hello\n";
    return 0;
}

我现在如何动态地将它与cppunit链接?以下尝试失败:

$ g++ -lcppunit test.cpp
Undefined symbols for architecture x86_64:
  "CppUnit::SourceLine::SourceLine(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
      FooTest::testBasic()     in ccyx1sc9.o
      FooTest::testBasic2()      in ccyx1sc9.o
  "CppUnit::AdditionalMessage::AdditionalMessage(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      void CppUnit::assertEquals<int>(int const&, int const&, CppUnit::SourceLine, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in ccyx1sc9.o
  "CppUnit::TestFactoryRegistry::getRegistry(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      CppUnit::AutoRegisterSuite<FooTest>::AutoRegisterSuite() in ccyx1sc9.o
...
...

0 个答案:

没有答案