我正在尝试使用clang ++来使用以下Crypto ++(加密方案的C ++类库)示例来处理iMac。
实施例
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架构的符号。
任何提示都将不胜感激。
答案 0 :(得分:3)
Crypto ++ 5.6.2使用make选项在LLVM版本6.1.0(clang-602.0.53)上成功构建:
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 ++需要MacOSX,请参阅:When is it necessary to use use the flag -stdlib=libstdc++?
答案 1 :(得分:2)
你需要在编译器命令中使用-lcryptopp
链接到提供这些符号的库,这些符号应该是libcryptopp.so
查看您的“构建命令”(这不是您正在运行的命令,它是您正在运行的命令的输出,如果您显示它将会更容易阅读实际的命令)似乎你正在将.cpp
文件编译成.o
文件,但是获取链接器错误,这很奇怪,因为生成.o
文件通常是步骤在链接之前。你想做什么步骤?也许您还需要添加-c
,因此它只会编译而不会尝试链接。链接时您仍需要-lcryptopp
。
答案 2 :(得分:1)
除了Jonathon的答案,因为当指定 -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)"
...
__1
表示您正在使用LLVM C ++运行时(libc++
)。在某些地方,您可能正在与GNU C ++运行时混合和匹配(libstdc++
)。 GNU C ++运行时(libstdc++
)在其符号上缺少__1
装饰。
您应该浏览项目 和 所有预先构建的库,并确保它们正在使用其中一个库。对于每个,您应该使用(1)CXXFLAGS
(LLVM)或(2)-stdlib=libc++
(GNU)的-stdlib=libstdc++
。
请注意,像Xcode这样的IDE可能会使用与Crypto ++不同的-stdlib=...
设置。在这种情况下,让Xcode与Crypto ++匹配,或者重建Crypto ++库以匹配Xcode。
如果Xcode正在使用LLVM的libc++
并且你必须重建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
是用于版本控制的内联命名空间。请参阅What are inline namespaces for?和Where does the __1 symbol come from when using LLVM's libc++?。
答案 3 :(得分:0)