Vtable problem with cppunit and xcode project

I am trying to create a zxing iphone project and run test packages written in cppunit-1.12.1. I copied the cppunit-1.12.1 code inside the project and changed the active SDK to 10.5, I can build the cppunit and zxingcore targets, but when I try to build the zxingcore-tests target, I get the following errors that seem to be related to vtables and weird warning related to the type of library architecture:

Is there a good way to format this, mostly by avoiding formatting without having to insert> infront of every line. I used tags <pre>

that worked well in the preview, but not in the final render - they didn't respect the formatting and cut out the text. I will change the formatting as soon as someone gives me a suggestion.


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...

And now mistakes


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

      

+2


source to share


3 answers


OK, here's what I think the problem is, but don't quote me on this one;)

The cppunit code uses a macro CPPUNIT_API

to wrap

__declspec(dllexport)

      

and

__declspec(dllimport)

      

when building on Win32. It does not use equivalent

__attribute__ ((visibility("default")))

      

for gcc

. This can cause problems when including this code in projects that use the visibility attributes in gcc

, especially when the project uses the command line flaggcc



-fvisibility=hidden

      

to make all symbols private in the library by default and then using

__attribute__((visibility("default")))

      

instead __declspec(dllexport/import)

where needed. If a symbol like a vtable is marked as hidden in one library, although it is marked as open in all other libraries, then obviously (see link below) it is marked as hidden and you get a linker error.

In your case, the linker warnings you receive initially assume that it zxingcore-tests

is being created with symbols hidden by default (check this setting -f

when creating it), while xzingcore

itself has them publicly available. Symbols for cppunit vtables will exist in cppunit

, zxingcore

and zxingcore-tests

, but are marked as hidden in zxingcore-test

, and so they are hidden.

I think you need to try and figure out why the assembly is zxingcore-tests

hiding symbols and preventing it from doing so.

For further reading try the gcc wiki visibility page , specifically the "C ++ Exception Issues" section (and follow the link about undefined linking there also shows that this applies to vtables as well). I am vaguely familiar with this stuff because I have been bitten by bugs dynamic_cast

in the libraries, which in this case are caused by objects being typeinfo

hit by mistake.

+3


source


I think the problem was that the cppunit and zxingcore libraries were being built for armv6, while the zxingcore tests were being built for Intel architecture. After choosing a config setting for zxingcore tests in NATIVE_ARCH, it seems to compile.



+2


source


I am having similar problems using libraries. I was able to troubleshoot the issues by making sure the following options were set in both build settings:

Under Target Info - Build - GCC 4.2 - Code Generation:

Make sure Built-in Methods Hidden and Symbols Hidden by Default are disabled.

It might be a bit of a sledgehammer technique, but it works. If anyone can suggest a more subtle way to fix this problem, I would appreciate it.

0


source







All Articles