macos - 将 Crypto++ 与 clang 一起使用

标签 macos crypto++ undefined-symbol clang++ missing-symbols

我正在尝试使用 clang++ 在 iMac 上运行以下 Crypto++(加密方案的 C++ 类库)示例。

例子

SHA256 hash;

byte digest[ SHA256::DIGESTSIZE ];

hash.CalculateDigest( digest, (byte*) &value[ 0 ], value.size( ) );

HexEncoder encoder;

string result = String::empty;

encoder.Attach( new StringSink( result ) );

encoder.Put( digest, sizeof( digest ) );

encoder.MessageEnd( );

构建命令

Apple clang version 2.1 (tags/Apple/clang-163.7.1) (based on LLVM 3.0svn)
Target: x86_64-apple-darwin11.4.0
Thread model: posix
 "/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.7.4 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name checksum_impl.cpp -pic-level 2 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 123.2.1 -v -resource-dir /usr/bin/../lib/clang/2.1 -D framework_EXPORTS -I /Users/Ben/Dropbox/appon/build/../source -nostdinc++ -cxx-isystem /usr/include/c++/v1 -Wall -Wextra -Weffc++ -pedantic -std=c++0x -fdeprecated-macro -ferror-limit 19 -fmessage-length 175 -stack-protector 1 -fblocks -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o CMakeFiles/framework.dir/Users/Ben/Dropbox/source/example.cpp.o -x c++ /Users/Ben/Dropbox/source/example.cpp
clang -cc1 version 2.1 based upon llvm 3.0svn hosted on x86_64-apple-darwin11.4.0
#include "..." search starts here:
#include <...> search starts here:
 /Users/Ben/Dropbox/build/../source
 /usr/include/c++/v1
 /usr/local/include
 /usr/bin/../lib/clang/2.1/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.

链接器输出

clang: warning: argument unused during compilation: '-std=c++0x'
Undefined symbols for architecture x86_64:
  "CryptoPP::Filter::TransferTo2(CryptoPP::BufferedTransformation&, unsigned long long&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)", referenced from:
      vtable for CryptoPP::SimpleProxyFilter in checksum_impl.cpp.o
      vtable for CryptoPP::Bufferless<CryptoPP::Filter> in checksum_impl.cpp.o
      vtable for CryptoPP::Unflushable<CryptoPP::Filter> in checksum_impl.cpp.o
  "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", referenced from:
      vtable for CryptoPP::SimpleProxyFilter in checksum_impl.cpp.o
      vtable for CryptoPP::Bufferless<CryptoPP::Filter> in checksum_impl.cpp.o
      vtable for CryptoPP::Unflushable<CryptoPP::Filter> in checksum_impl.cpp.o
  "CryptoPP::BufferedTransformation::ChannelCreatePutSpace(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long&)", referenced from:
      vtable for CryptoPP::SimpleProxyFilter in checksum_impl.cpp.o
      vtable for CryptoPP::Bufferless<CryptoPP::Filter> in checksum_impl.cpp.o
      vtable for CryptoPP::Unflushable<CryptoPP::Filter> in checksum_impl.cpp.o
  "CryptoPP::BufferedTransformation::ChannelPut2(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned char const*, unsigned long, int, bool)", referenced from:
      vtable for CryptoPP::SimpleProxyFilter in checksum_impl.cpp.o
      vtable for CryptoPP::Bufferless<CryptoPP::Filter> in checksum_impl.cpp.o
      vtable for CryptoPP::Unflushable<CryptoPP::Filter> in checksum_impl.cpp.o
  "CryptoPP::BufferedTransformation::ChannelPutModifiable2(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned char*, unsigned long, int, bool)", referenced from:
      vtable for CryptoPP::SimpleProxyFilter in checksum_impl.cpp.o
      vtable for CryptoPP::Bufferless<CryptoPP::Filter> in checksum_impl.cpp.o
      vtable for CryptoPP::Unflushable<CryptoPP::Filter> in checksum_impl.cpp.o
  "CryptoPP::BufferedTransformation::ChannelFlush(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, int, bool)", referenced from:
      vtable for CryptoPP::SimpleProxyFilter in checksum_impl.cpp.o
      vtable for CryptoPP::Bufferless<CryptoPP::Filter> in checksum_impl.cpp.o
  "CryptoPP::BufferedTransformation::ChannelMessageSeriesEnd(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool)", referenced from:
      vtable for CryptoPP::SimpleProxyFilter in checksum_impl.cpp.o
      vtable for CryptoPP::Bufferless<CryptoPP::Filter> in checksum_impl.cpp.o
      vtable for CryptoPP::Unflushable<CryptoPP::Filter> in checksum_impl.cpp.o
  "CryptoPP::BufferedTransformation::SetRetrievalChannel(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      vtable for CryptoPP::SimpleProxyFilter in checksum_impl.cpp.o
      vtable for CryptoPP::Bufferless<CryptoPP::Filter> in checksum_impl.cpp.o
      vtable for CryptoPP::Unflushable<CryptoPP::Filter> in checksum_impl.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)
make: *** [all] Error 2

我使用的是 Crypto++ 5.6.2 的最新开发版本,因为之前的版本 5.6.1 无法使用 clang++ 构建。但是我遇到了构建问题,指出我缺少 x86_64 架构的符号。

如有任何提示,我们将不胜感激。

最佳答案

Crypto++ 5.6.2 在 LLVM 版本 6.1.0 (clang-602.0.53) 上使用 make 选项成功构建:

CXXFLAGS="-std=c++11 -stdlib=libstdc++ -DCRYPTOPP_DISABLE_ASM -Wno-c++11-narrowing"

因此这个脚本:https://github.com/mapnik/mapnik-packaging/blob/master/osx/scripts/build_cryptopp.sh

-stdlib=libstdc++ 自 Mavericks 以来需要 MacOSX,参见:When is it necessary to use use the flag -stdlib=libstdc++?

关于macos - 将 Crypto++ 与 clang 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10869706/

相关文章:

c++ - 在 python 中使用链接库中的方法时出现属性错误

c - Mex无法正确链接,导致 "dyld: lazy symbol binding failed: Symbol not found: _mxGetNumberOfDimensions_700"

excel - 如果列中的字符串左对齐,如何获取信息以及如何在另一个工作表中使用此信息创建新单元格?

objective-c - OSX 多个 nswindow 位于另一个窗口中

macos - 如何在终端中显示当前分支和文件夹路径?

c++ - 调试断言失败

c++ - 为 OS X Xcode 项目编译 Crypto++ 库

c++ - Crypto++ 在 algparam.h 中给出编译器错误

c++ - 是什么导致 "Undefined symbols for architecture x86_64"构建错误?

objective-c++ - Xcode 4.6.3 中自定义 C++ 类的 undefined symbol 。适用于 Xcode 4.5.2