cppunit在Mac OS X上与Clang链接错误
CppUnit Linking error with Clang on Mac OS X
我正在尝试使用cppunit编译测试程序。问题是,使用此示例代码:
//[...]
class EntityComponentTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( EntityComponentTest );
CPPUNIT_TEST( testGetComponents );
CPPUNIT_TEST_SUITE_END();
Entity e;
public:
void setUp(){
e.addComponent("1", new TestComponent("Hello 1"));
e.addComponent("2", new TestComponent("Hello 2"));
}
void tearDown(){}
void testGetComponents()
{
TestComponent &first = static_cast<TestComponent&>(e.getComponent("1"));
TestComponent &second = static_cast<TestComponent&>(e.getComponent("2"));
CPPUNIT_ASSERT(first.msg == "Hello 1");
CPPUNIT_ASSERT(second.msg == "Hello 2");
}
};
CPPUNIT_TEST_SUITE_REGISTRATION( EntityComponentTest );
int main(void)
{
//followed from tutorial
CppUnit::TextUi::TestRunner run;
CppUnit::TestFactoryRegistry &r = CppUnit::TestFactoryRegistry::getRegistry();
run.addTest(r.makeTest());
run.run("", false, true);
return 0;
}
我正在收到链接错误:
Undefined symbols for architecture x86_64:
"CppUnit::SourceLine::SourceLine(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
EntityComponentTest::testGetComponents() in EntityComponentTest.cpp.o
"CppUnit::TextTestRunner::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool)", referenced from:
_main in EntityComponentTest.cpp.o
"CppUnit::TestFactoryRegistry::getRegistry(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in EntityComponentTest.cpp.o
CppUnit::AutoRegisterSuite<EntityComponentTest>::AutoRegisterSuite() in EntityComponentTest.cpp.o
"CppUnit::Message::Message(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
EntityComponentTest::testGetComponents() in EntityComponentTest.cpp.o
"CppUnit::TestCase::TestCase(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
CppUnit::TestCaller<EntityComponentTest>::TestCaller(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void (EntityComponentTest::*)(), EntityComponentTest*) in EntityComponentTest.cpp.o
"CppUnit::TestSuite::TestSuite(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
EntityComponentTest::suite() in EntityComponentTest.cpp.o
"CppUnit::TestSuiteBuilderContextBase::getTestNameFor(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
EntityComponentTest::addTestsToSuite(CppUnit::TestSuiteBuilderContextBase&) in EntityComponentTest.cpp.o
"CppUnit::Test::findTestPath(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, CppUnit::TestPath&) const", referenced from:
vtable for CppUnit::TestCaller<EntityComponentTest> in EntityComponentTest.cpp.o
"CppUnit::Test::resolveTestPath(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
vtable for CppUnit::TestCaller<EntityComponentTest> in EntityComponentTest.cpp.o
"CppUnit::Test::findTest(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
vtable for CppUnit::TestCaller<EntityComponentTest> in EntityComponentTest.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我在调用clang时使用-lcppunit标志。当我在Linux计算机上运行Make File时,它会罚款。
libcppunit-1.12.1.0.0.dylib
libcppunit-1.12.1.dylib
libcppunit.a
libcppunit.dylib
在我/usr/local/lib/中。我什至尝试安装到/usr/lib,并发生相同的链接错误。任何帮助将不胜感激。
非常感谢!
编辑:我发现了问题。我正在使用libc ,因为我在项目中使用了std :: shared_ptr。问题是我尝试用libc 编译cppunit,但会引发链接错误。看来它必须与libstdc 一起编译,这需要我安装Fink或MacPorts,以便我可以安装最新版本的GCC和LibstDC 。我真的希望避免这种情况,因为会有一团糟的尝试来设置它。我真的也希望避免将Boost用于共享_ptr。
有可能吗?如果没有,我可能会屈服并安装Macports
我也有同样的问题。将" C 标准库"设置为" libstdc (GNU C 标准库)"。
相关文章:
- 我可以将一个用clang c++11编译的对象与另一个用c++17编译的对象链接起来吗
- Clang 8 带有静态 constexpr 和数组的链接器错误 - 错误是什么以及如何解决它?
- Eclipse CDT clang 工具链 - 无法从链接器选项中删除 stdlibc++,但可以添加 libc++,E
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- std::to_chars在MacOS/clang上编译但不链接
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 程序使用boost::文件系统链接clang,但不使用gcc
- CLang++ 链接器未定义的符号用于体系结构x86_64
- clang链接.so库libc _共享
- cppunit在Mac OS X上与Clang链接错误
- clang++链接失败:错误:源文件不是有效的UTF-8
- 在窗口上使用 clang 链接 msvc 内部函数时出现问题
- 重载抽象运算符=时出现Clang链接器错误
- Mac OSX上的Clang链接错误
- 使用clang链接静态库,与顺序无关
- Clang链接时间优化与替换的操作员新的原因不匹配的自由()/删除在valgrind
- Clang链接使用.so文件
- c/c++ clang链接错误在Mac OSX - webkitgtk
- Clang链接器问题和获取调试信息