我正在尝试构建zxing iphone项目并运行以cppunit-1.12.1编写的测试套件。我在项目内部复制了cppunit-1.12.1代码,并将 Activity 的SDK更改为10.5,我能够构建cppunit和zxingcore目标,但是当我尝试构建zxingcore-tests目标时,出现以下错误,似乎与vtables有关,并且奇怪的警告与库的体系结构类型有关:
通过基本转义格式设置而不必在每行前面插入>,是否有一种格式化此格式的好方法。我使用了<pre>
标记,该标记在预览中效果很好,但在最终渲染中效果不佳-不尊重格式设置并切断了文本。有人给我建议后,我将立即修改格式。
Ld build/Debug/zxingcore-tests normal i386
cd /Users/andres/src/zxing/iphone
setenv MACOSX_DEPLOYMENT_TARGET 10.5
/Developer/usr/bin/g++-4.2 -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk -L/Users/andres/src/zxing/iphone/build/Debug -F/Users/andres/src/zxing/iphone/build/Debug -filelist /Users/andres/src/zxing/iphone/build/ZXing.build/Debug/zxingcore-tests.build/Objects-normal/i386/zxingcore-tests.LinkFileList -mmacosx-version-min=10.5 -lzxingcore -lCppUnit -o /Users/andres/src/zxing/iphone/build/Debug/zxingcore-tests
ld: warning: in /Developer/SDKs/MacOSX10.5.sdk/usr/local/lib/libCppUnit.dylib, file is not of required architecture
ld: warning: common::Counted::Counted()has different visibility (default) in /Users/andres/src/zxing/iphone/build/Debug/libzxingcore.a(GF256.o) and (hidden) in /Users/andres/src/zxing/iphone/build/ZXing.build/Debug/zxingcore-tests.build/Objects-normal/i386/BitSourceTest.o
ld: warning: common::Counted::retain() has different visibility (default) in /Users/andres/src/zxing/iphone/build/Debug/libzxingcore.a(GF256.o) and (hidden) in /Users/andres/src/zxing/iphone/build/ZXing.build/Debug/zxingcore-tests.build/Objects-normal/i386/BitSourceTest.o
ld: warning: common::ArrayRef::~ArrayRef()has different visibility (default) in /Users/andres/src/zxing/iphone/build/Debug/libzxingcore.a(GF256.o) and (hidden) in /Users/andres/src/zxing/iphone/build/ZXing.build/Debug/zxingcore-tests.build/Objects-normal/i386/ReedSolomonTest.o
ld: warning: std::valarray::operator[](unsigned long)has different visibility (default) in /Users/andres/src/zxing/iphone/build/Debug/libzxingcore.a(GF256.o) and (hidden) in /Users/andres/src/zxing/iphone/build/ZXing.build/Debug/zxingcore-tests.build/Objects-normal/i386/ReedSolomonTest.o
ld: warning: common::ArrayRef::reset(common::Array*)has different visibility (default) in /Users/andres/src/zxing/iphone/build/Debug/libzxingcore.a(GF256.o) and (hidden) in /Users/andres/src/zxing/iphone/build/ZXing.build/Debug/zxingcore-tests.build/Objects-normal/i386/ReedSolomonTest.o
ld: warning: common::ArrayRef::ArrayRef(common::Array*)has different visibility (default) in /Users/andres/src/zxing/iphone/build/Debug/libzxingcore.a(GF256.o) and (hidden) in /Users/andres/src/zxing/iphone/build/ZXing.build/Debug/zxingcore-tests.build/Objects-normal/i386/ReedSolomonTest.o
ld: warning: common::ArrayRef::ArrayRef(common::ArrayRef const&)has different visibility (default) in /Users/andres/src/zxing/iphone/build/Debug/libzxingcore.a(GF256.o) and (hidden) in /Users/andres/src/zxing/iphone/build/ZXing.build/Debug/zxingcore-tests.build/Objects-normal/i386/ReedSolomonTest.o
....many more of these warnings...
现在的错误
Undefined symbols: "vtable for CppUnit::TestSuiteBuilderContextBase", referenced from: __ZTVN7CppUnit27TestSuiteBuilderContextBaseE$non_lazy_ptr in BitArrayTest.o __ZTVN7CppUnit27TestSuiteBuilderContextBaseE$non_lazy_ptr in BitMatrixTest.o __ZTVN7CppUnit27TestSuiteBuilderContextBaseE$non_lazy_ptr in BitSourceTest.o __ZTVN7CppUnit27TestSuiteBuilderContextBaseE$non_lazy_ptr in BlackPointEstimatorTest.o __ZTVN7CppUnit27TestSuiteBuilderContextBaseE$non_lazy_ptr in PerspectiveTransformTest.o __ZTVN7CppUnit27TestSuiteBuilderContextBaseE$non_lazy_ptr in ReedSolomonTest.o __ZTVN7CppUnit27TestSuiteBuilderContextBaseE$non_lazy_ptr in DataMaskTest.o __ZTVN7CppUnit27TestSuiteBuilderContextBaseE$non_lazy_ptr in ErrorCorrectionLevelTest.o __ZTVN7CppUnit27TestSuiteBuilderContextBaseE$non_lazy_ptr in FormatInformationTest.o __ZTVN7CppUnit27TestSuiteBuilderContextBaseE$non_lazy_ptr in ModeTest.o __ZTVN7CppUnit27TestSuiteBuilderContextBaseE$non_lazy_ptr in VersionTest.o "CppUnit::TestLeaf::doGetChildTestAt(int) const", referenced from: vtable for CppUnit::TestCaller in BitArrayTest.o vtable for CppUnit::TestCaller in BitMatrixTest.o vtable for CppUnit::TestCaller in BitSourceTest.o vtable for CppUnit::TestCaller in BlackPointEstimatorTest.o vtable for CppUnit::TestCaller in PerspectiveTransformTest.o vtable for CppUnit::TestCaller in ReedSolomonTest.o vtable for CppUnit::TestCallerin DataMaskTest.o vtable for CppUnit::TestCallerin ErrorCorrectionLevelTest.o vtable for CppUnit::TestCallerin FormatInformationTest.o vtable for CppUnit::TestCallerin ModeTest.o vtable for CppUnit::TestCallerin VersionTest.o "typeinfo for CppUnit::TestCase", referenced from: typeinfo for CppUnit::TestCallerin BitArrayTest.o typeinfo for CppUnit::TestCallerin BitMatrixTest.o typeinfo for CppUnit::TestCallerin BitSourceTest.o typeinfo for CppUnit::TestCallerin BlackPointEstimatorTest.o typeinfo for CppUnit::TestCallerin PerspectiveTransformTest.o typeinfo for CppUnit::TestCallerin ReedSolomonTest.o typeinfo for CppUnit::TestCallerin DataMaskTest.o typeinfo for CppUnit::TestCallerin ErrorCorrectionLevelTest.o typeinfo for CppUnit::TestCallerin FormatInformationTest.o typeinfo for CppUnit::TestCallerin ModeTest.o typeinfo for CppUnit::TestCallerin VersionTest.o "CppUnit::TestLeaf::countTestCases() const", referenced from: vtable for CppUnit::TestCaller in BitArrayTest.o vtable for CppUnit::TestCaller in BitMatrixTest.o vtable for CppUnit::TestCaller in BitSourceTest.o vtable for CppUnit::TestCaller in BlackPointEstimatorTest.o vtable for CppUnit::TestCaller in`... lots of these errors ... `CppUnit::assertEquals(qrcode::decoder::FormatInformation const&, qrcode::decoder::FormatInformation const&, CppUnit::SourceLine, std::basic_string, std::allocator > const&)in FormatInformationTest.o void CppUnit::assertEquals(int const&, int const&, CppUnit::SourceLine, std::basic_string, std::allocator > const&)in ModeTest.o void CppUnit::assertEquals(qrcode::decoder::Mode* const&, qrcode::decoder::Mode* const&, CppUnit::SourceLine, std::basic_string, std::allocator > const&)in ModeTest.o void CppUnit::assertEquals(int const&, int const&, CppUnit::SourceLine, std::basic_string, std::allocator > const&)in VersionTest.o void CppUnit::assertEquals(bool const&, bool const&, CppUnit::SourceLine, std::basic_string, std::allocator > const&)in VersionTest.old: symbol(s) not foundcollect2: ld returned 1 exit status
最佳答案
好的,这就是我认为的问题所在,但请不要在此引用我的意见;)
cppunit代码使用CPPUNIT_API
宏进行包装
__declspec(dllexport)
和
__declspec(dllimport)
在Win32上构建时。它不使用等效
__attribute__ ((visibility("default")))
用于
gcc
。在确实使用gcc
中的可见性属性的项目中包含该代码时,这可能会导致问题,特别是当项目使用gcc
命令行标志时-fvisibility=hidden
默认情况下将所有符号专用于库
__attribute__((visibility("default")))
在适当的地方代替
__declspec(dllexport/import)
。如果一个符号(例如vtable)仅在一个库中被标记为隐藏,即使该符号在所有其他库中被标记为公共(public),则显然(请参见下面的链接)该符号也被标记为隐藏,并且出现链接器错误。在您的情况下,您最初收到的链接器警告表明
zxingcore-tests
的构建默认情况下是隐藏的符号(构建时检查该-f
选项),而xzingcore
本身将其公开。 cppunit vtable的符号将存在于cppunit
,zxingcore
和zxingcore-tests
中,但在zxingcore-test
中标记为隐藏,因此它们被隐藏了。我认为您需要尝试找出
zxingcore-tests
构建为何隐藏符号并阻止它这样做的原因。为了进一步阅读,请尝试gcc wiki visibility page,尤其是有关“C++异常的问题”的部分(并在其中关注关于模糊链接的链接,这也表明它也适用于vtables)。我对这些东西有些含糊,因为我被跨库的
dynamic_cast
故障所困扰,在这种情况下,这些错误是由于typeinfo
对象被错误隐藏而造成的。关于c++ - cppunit和xcode项目的vtable问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1429475/