Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
735 views
in Technique[技术] by (71.8m points)

c++ - Undefined symbols in Crypto++/iOS 64-bit project

I tried to build with github's prebuilt cryptopp but it doesn't work, too. it occur errors like below:

Undefined symbols for architecture arm64: "CryptoPP::BufferedTransformation::ChannelFlush(std::string const&, bool, int, bool)", referenced from:

 vtable for CryptoPP::SimpleProxyFilter in MYCLASSBBB.o
 vtable for CryptoPP::Bufferless<CryptoPP::Filter> in MYCLASSBBB.o

"CryptoPP::Filter::CopyRangeTo2(CryptoPP::BufferedTransformation&, unsigned long long&, unsigned long long, std::string const&, bool) const", referenced from:

 vtable for CryptoPP::Base64Decoder in MYCLASSBBB.o
 vtable for CryptoPP::Unflushable<CryptoPP::Filter> in MYCLASSBBB.o
 vtable for CryptoPP::SimpleProxyFilter in MYCLASSBBB.o
 vtable for CryptoPP::Bufferless<CryptoPP::Filter> in MYCLASSBBB.o

"CryptoPP::Filter::TransferTo2(CryptoPP::BufferedTransformation&, unsigned long long&, std::string const&, bool)", referenced from:

 vtable for CryptoPP::Base64Decoder in MYCLASSBBB.o
 vtable for CryptoPP::Unflushable<CryptoPP::Filter> in MYCLASSBBB.o
 vtable for CryptoPP::SimpleProxyFilter in MYCLASSBBB.o
 vtable for CryptoPP::Bufferless<CryptoPP::Filter> in MYCLASSBBB.o

"CryptoPP::BufferedTransformation::ChannelPut2(std::string const&, unsigned char const*, unsigned long, int, bool)", referenced from:

 vtable for CryptoPP::Base64Decoder in MYCLASSBBB.o
 vtable for CryptoPP::Unflushable<CryptoPP::Filter> in MYCLASSBBB.o
 vtable for CryptoPP::SimpleProxyFilter in MYCLASSBBB.o
 vtable for CryptoPP::Bufferless<CryptoPP::Filter> in MYCLASSBBB.o

"CryptoPP::BufferedTransformation::ChannelCreatePutSpace(std::string const&, unsigned long&)", referenced from:

 vtable for CryptoPP::Base64Decoder in MYCLASSBBB.o
 vtable for CryptoPP::Unflushable<CryptoPP::Filter> in MYCLASSBBB.o
 vtable for CryptoPP::SimpleProxyFilter in MYCLASSBBB.o
 vtable for CryptoPP::Bufferless<CryptoPP::Filter> in MYCLASSBBB.o

"CryptoPP::BufferedTransformation::ChannelPutModifiable2(std::string const&, unsigned char*, unsigned long, int, bool)", referenced from:

 vtable for CryptoPP::Base64Decoder in MYCLASSBBB.o
 vtable for CryptoPP::Unflushable<CryptoPP::Filter> in MYCLASSBBB.o
 vtable for CryptoPP::SimpleProxyFilter in MYCLASSBBB.o
 vtable for CryptoPP::Bufferless<CryptoPP::Filter> in MYCLASSBBB.o

"CryptoPP::BufferedTransformation::ChannelMessageSeriesEnd(std::string const&, int, bool)", referenced from:

 vtable for CryptoPP::Base64Decoder in MYCLASSBBB.o
 vtable for CryptoPP::Unflushable<CryptoPP::Filter> in MYCLASSBBB.o
 vtable for CryptoPP::SimpleProxyFilter in MYCLASSBBB.o
 vtable for CryptoPP::Bufferless<CryptoPP::Filter> in MYCLASSBBB.o

"CryptoPP::BufferedTransformation::SetRetrievalChannel(std::string const&)", referenced from:

 vtable for CryptoPP::Base64Decoder in MYCLASSBBB.o
 vtable for CryptoPP::Unflushable<CryptoPP::Filter> in MYCLASSBBB.o
 vtable for CryptoPP::SimpleProxyFilter in MYCLASSBBB.o
 vtable for CryptoPP::Bufferless<CryptoPP::Filter> in MYCLASSBBB.o

"CryptoPP::StringSinkTemplate::StringSinkTemplate(std::string&)", referenced from:

 encryptString(std::string const&) in MYCLASSBBB.o
 decryptString(std::string const&, int) in MYCLASSBBB.o
 MYCLASSAAA::setDeviceId() in MYCLASSAAA.o
 MYCLASSAAA::getSignature() in MYCLASSAAA.o

ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

the MYCLASSAAA and MYCLASSBBB are all of classes what using cryptopp lib. it using cryptlib.h, modes.h, filters.h, aes.h, base64.h, md5.h, hex.h.

I even tried to build the lib myself, but I it same errors happen. what should I do?

I hope your help. thanks.


add the xcode cmd

Ld /Users/USERNAME/Library/Developer/Xcode/DerivedData/PROJECT_NAME-aknkujyaqvqjswbhspmawywtyqee/Build/Products/Release-iphoneos/PROJECT_NAME.app/PROJECT_NAME normal arm64 cd /Users/USERNAME/Desktop/Development/Office_Projects/PROJECTROOT/root export IPHONEOS_DEPLOYMENT_TARGET=5.1.1 export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -L/Users/USERNAME/Library/Developer/Xcode/DerivedData/PROJECT_NAME-aknkujyaqvqjswbhspmawywtyqee/Build/Products/Release-iphoneos -L/Users/USERNAME/Desktop/Development/Office_Projects/PROJECTROOT/root/PROJECT_NAME/libs/cocos2dx/platform/third_party/ios/libraries -L/Users/USERNAME/Desktop/Development/Office_Projects/PROJECTROOT/root/PROJECT_NAME/libs/EEAF-SDK7.0(i386,armv7,armv7s,arm64) -L/Users/USERNAME/Desktop/Development/Office_Projects/PROJECTROOT/root/PROJECT_NAME/libs/boost_1_57/ios -L/Users/USERNAME/Desktop/Development/Office_Projects/PROJECTROOT/root/PROJECT_NAME/Classes/cryptopp/lib -LPROJECT_NAME/cocos2dx/platform/third_party/ios/libraries -LPROJECT_NAME/EEAF-SDK7.0(i386,armv7,armv7s,arm64) -F/Users/USERNAME/Library/Developer/Xcode/DerivedData/PROJECT_NAME-aknkujyaqvqjswbhspmawywtyqee/Build/Products/Release-iphoneos -F/Users/USERNAME/Desktop/Development/Office_Projects/PROJECTROOT/root/PROJECT_NAME/libs -filelist /Users/USERNAME/Library/Developer/Xcode/DerivedData/PROJECT_NAME-aknkujyaqvqjswbhspmawywtyqee/Build/Intermediates/PROJECT_NAME.build/Release-iphoneos/PROJECT_NAME.build/Objects-normal/arm64/PROJECT_NAME.LinkFileList -dead_strip -lxml2 -lz -ObjC -lcryptopp -fobjc-link-runtime -miphoneos-version-min=5.1.1 -lc++ /Users/USERNAME/Desktop/Development/Office_Projects/PROJECTROOT/root/PROJECT_NAME/libs/boost_1_57/ios/boost.a -framework UIKit -framework CoreTelephony -lEEAF -framework FacebookSDK -framework AddressBook -framework AddressBookUI -framework AudioToolbox -framework AVFoundation -framework CFNetwork -framework CoreGraphics -framework CoreLocation -framework CoreMedia -framework CoreText -framework Foundation -framework ImageIO -framework MediaPlayer -framework MobileCoreServices -framework OpenAL -framework OpenGLES -framework QuartzCore -framework Security -framework SystemConfiguration -lsqlite3.0 -framework StoreKit -lcurl -Xlinker -dependency_info -Xlinker /Users/USERNAME/Library/Developer/Xcode/DerivedData/PROJECT_NAME-aknkujyaqvqjswbhspmawywtyqee/Build/Intermediates/PROJECT_NAME.build/Release-iphoneos/PROJECT_NAME.build/Objects-normal/arm64/PROJECT_NAME_dependency_info.dat -o /Users/USERNAME/Library/Developer/Xcode/DerivedData/PROJECT_NAME-aknkujyaqvqjswbhspmawywtyqee/Build/Products/Release-iphoneos/PROJECT_NAME.app/PROJECT_NAME

and "vtable for CRYPTOPP::~.o" always happen. with a notice :

NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Undefined symbols for architecture arm64: "CryptoPP::BufferedTransformation::ChannelFlush(std::string const&, bool, int, bool)", referenced from:

 vtable for CryptoPP::SimpleProxyFilter in MYCLASSBBB.o
 vtable for CryptoPP::Bufferless<CryptoPP::Filter> in MYCLASSBBB.o

I think you are not using libc++, which is LLVM's C++ standard library. I think that because I don't see a -stdlib=libc++ (but I don't recall if that's passed to ld directly).

The symbol is defined in the github's prebuilt cryptopp (that's my github, btw). Here's how to verify.

First, extract the arm64 library from the fat library:

$ xcrun -sdk iphoneos lipo libcryptopp.a -thin arm64 -output libcryptopp-arm64.a
$ ls
libcryptopp-arm64.a libcryptopp.a

Next, use nm to dump global symbols, and use c++filt to demangle:

$ nm -g libcryptopp-arm64.a | c++filt | grep BufferedTransformation::ChannelFlush | grep " T "
0000000000002110 T CryptoPP::BufferedTransformation::ChannelFlush(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, int, bool)

The capitol T means you are searching for symbols that are defined and exported. Lower t means its defined but not exported - i.e., private. Capitol U means its undefined.

The __1 is what libc++ (LLVM) uses to differentiate from libstdc++ (GNU). std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > is a string, so that could be rewritten as:

CryptoPP::BufferedTransformation::ChannelFlush(std::__1::string const&, bool, int, bool)

If this library was built against libstdc++ (GNU), then the symbol from the library would be:

CryptoPP::BufferedTransformation::ChannelFlush(std:::string const&, bool, int, bool)

We can repeat for the second problem child, and it follows the same pattern (libc++, and not libstdc++):

$ nm -g libcryptopp-arm64.a | c++filt | grep CryptoPP::Filter::CopyRangeTo2 | grep " T "
00000000000001c4 T CryptoPP::Filter::CopyRangeTo2(CryptoPP::BufferedTransformation&, unsigned long long&, unsigned long long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) const

This can be rewritten as:

CryptoPP::Filter::CopyRangeTo2(CryptoPP::BufferedTransformation&, unsigned long long&, unsigned long long, std::__1::string const&, bool) const

-----

IF you need GNU's libstdc++, then you can build it yourself. Here are the steps:

  1. Download and unpack Crypto++ from the website
  2. Download and unpack cryptopp-mobile.zip. Unpack it right over top the Crypto++ source files
  3. Open the new GNUmakefile, find the iOS rule by searching for the block that begins with IS_IOS
  4. Change this line in the IS_IOS block: CXXFLAGS += -stdlib=libc++. Change it to CXXFLAGS += -stdlib=libstdc++
  5. Do the cross compile...

-----

I downloaded Cocos2D-x and tried to look at its configuration (I'm not a Cmake guy, so I could be wrong with what follows). It has the following in CmakeList.txt:

if(MSVC)
  ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
                  -wd4251 -wd4244 -wd4334 -wd4005 -wd4820 -wd4710
                  -wd4514 -wd4056 -wd4996 -wd4099)
else()
  set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1")
  set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-exceptions -std=c99")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -std=c++11 -Wno-deprecated-declarations -Wno-reorder")
  if(CLANG)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  endif()
endif(MSVC)

If Cmake is doing what I suspect, then its using LLVM's libc++. But its also using -std=c++11, and the GitHub project is not using it. But I'm not sure -std=c++11 makes a difference here.

Just bike shedding, but this is a bad sign: _SCL_SECURE_NO_WARNINGS. If they are blatantly doing that, then they probably have various degrees of of badness and brokenness. (Just my experience with auditing software).


If interested, the __1 is an inline namespace used for versioning. See What are inline namespaces for? and Where does the __1 symbol come from when using LLVM's libc++?.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...