2

我正在尝试构建 zxing iphone 项目并运行用 cppunit-1.12.1 编写的测试套件。我在项目中复制了 cppunit-1.12.1 代码,并将活动 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.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
 
4

3 回答 3

3

好的,这就是我认为的问题所在,但不要引用我的话;)

cppunit 代码使用CPPUNIT_API宏包起来

__declspec(dllexport)

__declspec(dllimport)

在 Win32 上构建时。它不使用等价物

__attribute__ ((visibility("default")))

gcc. 当在项目中包含该代码时,这可能会导致问题,这些项目确实使用了 中的可见性属性gcc,尤其是当项目使用gcc命令行标志时

-fvisibility=hidden

默认情况下使所有符号对库私有,然后使用

__attribute__((visibility("default")))

在适当的地方代替__declspec(dllexport/import)。如果一个符号(例如 vtable)仅在一个库中被标记为隐藏,即使它在所有其他库中被标记为公共,那么显然(参见下面的链接)它被标记为隐藏并且您会收到链接器错误。

在您的情况下,您最初收到的链接器警告建议zxingcore-tests使用默认隐藏的符号构建(在构建时检查该-f选项),而xzingcore它本身将它们公开。cppunit vtables 的符号将存在于 中,cppunit但被标记为隐藏,因此它们被隐藏。zxingcorezxingcore-testszxingcore-test

我认为您需要尝试找出zxingcore-tests构建隐藏符号的原因并阻止它这样做。

如需进一步阅读,请尝试gcc wiki 可见性页面,尤其是“C++ 异常问题”部分(并点击此处关于模糊链接的链接,该链接也表明它也适用于 vtables)。我对这些东西有点熟悉,因为我一直被dynamic_cast库之间的故障所困扰,在这种情况下,这些故障是由于typeinfo对象被错误地隐藏造成的。

于 2009-09-15T23:00:43.697 回答
2

我认为问题在于 cppunit 和 zxingcore 库是为 armv6 构建的,而 zxingcore-tests 是为英特尔架构构建的。在将 zxingcore-tests 的配置设置更改为 NATIVE_ARCH 后,它似乎可以正常编译。

于 2009-09-17T20:34:20.237 回答
0

我在使用库时也遇到过类似的问题。通过确保在两个项目的构建设置中设置以下内容,我已经能够解决问题:

在目标信息 - 构建 - GCC 4.2 - 代码生成下:

确保“隐藏的内联方法”和“默认隐藏的符号”都已关闭。

这可能有点像大锤技术,但它确实有效。如果有人可以提出更细粒度的方法来解决此问题,我将不胜感激。

于 2010-07-15T04:06:28.853 回答