3

我正在尝试使用 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 架构的符号。

任何提示将不胜感激。

4

4 回答 4

3

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,请参阅:何时需要使用 -stdlib=libstdc++ 标志?

于 2015-09-04T17:18:08.663 回答
2

您需要链接到提供这些符号的库,应该是 libcryptopp.so,-lcryptopp在编译器命令中使用

查看您的“构建命令”(这不是您正在运行的命令,它是您正在运行的命令的输出,如果您显示实际命令会更容易阅读)似乎您正在编译.cpp将文件写入.o文件,但出现链接器错误,这很奇怪,因为生成.o文件通常是链接之前的步骤。你想做什么步骤?也许您还需要添加-c,以便它只编译而不尝试链接。链接时仍然需要-lcryptopp

于 2012-06-28T20:12:52.587 回答
1

除了乔纳森的回答,因为这是一个相当普遍的问题,当 -lcryptopp被指定时......

架构 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)"...

表示您正在使用__1LLVM C++ 运行时 ( libc++)。在某个地方,您可能正在与 GNU C++ 运行时 ( libstdc++) 混合和匹配。GNU C++ 运行时 ( libstdc++) 缺少__1其符号的修饰。

您应该浏览项目所有预构建的库,并确保它们使用其中一个。对于每个,您应该使用CXXFLAGS(1) -stdlib=libc++(LLVM) 或 (2) -stdlib=libstdc++(GNU)。

请注意,像 Xcode 这样的 IDE 可能使用-stdlib=...与 Crypto++ 不同的设置。在这种情况下,让 Xcode 匹配 Crypto++,或者重建 Crypto++ 库以匹配 Xcode。

如果 Xcode 正在使用 LLVMlibc++并且您必须重新构建 Crypto++,则打开GNUmakefile并重新处理此部分(大约第 90 行):

ifeq ($(UNAME),Darwin)
  AR = libtool
  ARFLAGS = -static -o
  CXX = c++
  IS_GCC2 = $(shell $(CXX) -v 2>&1 | $(EGREP) -c gcc-932)
ifeq ($(IS_GCC2),1)
    CXXFLAGS += -fno-coalesce-templates -fno-coalesce-static-vtables
    LDLIBS += -lstdc++
    LDFLAGS += -flat_namespace -undefined suppress -m
endif
endif

如果你想使用 LLVM 的libc++,那么删除:

# GNU C++ Runtime
LDLIBS += -lstdc++

并添加:

# LLVM C++ Runtime
CXXFLAGS += -stdlib=libc++

为了完整起见,如果您想使用 GNU 的运行时,请删除LDLIBS += -lstdc++并添加CXXFLAGS += -stdlib=libstdc++.

如果未在环境或命令行中指定,您也可以更改CXX = c++CXX ?= c++makefile 将使用它。c++


如果感兴趣,这__1是一个用于版本控制的内联命名空间。请参阅什么是内联命名空间?使用 LLVM 的 libc++ 时,__1 符号从何而来?.

于 2015-03-27T04:02:00.407 回答
0

这个问题与 Crypto++ 没有被移植到 llvm-clang++ 有关。有关支持的编译器,请参见此处。

我的解决方案是使用GCrypt

抱歉,我无法提供有关失败原因的更多详细信息。

于 2012-07-14T15:22:07.390 回答