无法编译具有 snappy 支持的 leveldb
Unable to compile leveldb with snappy support
我正在尝试在 mac os x high sierra 上构建 https://github.com/google/leveldb with support for https://github.com/google/snappy 压缩以供以后在 XCode 项目中使用,我正在完成标准编译过程两个项目的自述文件中都有描述。这包括通过 cmake
为两个项目构建项目。在 snappy
项目的情况下,过程很顺利,一切都可以完美地构建和安装。但是在 leveldb
的情况下,我无法让 cmake
找到我之前通过 make install
安装的 snappy
库。我不明白如何调试 cmake
并找到它查找库的位置。
感谢任何帮助。
以下是两个构建的结果:
编辑
这是一个输出,似乎 /usr/local/lib 在列表中
另一个编辑
我已经按照 sel-fish
提供的解决方案尝试了 运行 cc -DCHECK_FUNCTION_EXISTS=snappy_compress -Wl,-search_paths_first -Wl,-headerpad_max_install_names -o check_snappy_exist CheckFunctionExists.c -lsnappy
。但如果失败并显示以下输出:
Undefined symbols for architecture x86_64:
"std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"std::logic_error::logic_error(char const*)", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"std::length_error::~length_error()", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::resize(unsigned long, char)", referenced from:
snappy::Uncompress(char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) in libsnappy.a(snappy.cc.o)
snappy::Compress(char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) in libsnappy.a(snappy.cc.o)
"std::terminate()", referenced from:
___clang_call_terminate in libsnappy.a(snappy.cc.o)
"typeinfo for std::length_error", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"vtable for __cxxabiv1::__class_type_info", referenced from:
typeinfo for snappy::Sink in libsnappy.a(snappy-sinksource.cc.o)
typeinfo for snappy::Source in libsnappy.a(snappy-sinksource.cc.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for __cxxabiv1::__si_class_type_info", referenced from:
typeinfo for snappy::ByteArraySource in libsnappy.a(snappy-sinksource.cc.o)
typeinfo for snappy::UncheckedByteArraySink in libsnappy.a(snappy-sinksource.cc.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for std::length_error", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"operator delete[](void*)", referenced from:
snappy::Compress(snappy::Source*, snappy::Sink*) in libsnappy.a(snappy.cc.o)
snappy::SnappySinkAllocator::Deleter(void*, char const*, unsigned long) in libsnappy.a(snappy.cc.o)
"operator delete(void*)", referenced from:
snappy::UncompressAsMuchAsPossible(snappy::Source*, snappy::Sink*) in libsnappy.a(snappy.cc.o)
snappy::Uncompress(snappy::Source*, snappy::Sink*) in libsnappy.a(snappy.cc.o)
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
snappy::ByteArraySource::~ByteArraySource() in libsnappy.a(snappy-sinksource.cc.o)
snappy::UncheckedByteArraySink::~UncheckedByteArraySink() in libsnappy.a(snappy-sinksource.cc.o)
"operator new[](unsigned long)", referenced from:
snappy::internal::WorkingMemory::GetHashTable(unsigned long, int*) in libsnappy.a(snappy.cc.o)
snappy::Compress(snappy::Source*, snappy::Sink*) in libsnappy.a(snappy.cc.o)
snappy::SnappyScatteredWriter<snappy::SnappySinkAllocator>::SlowAppend(char const*, unsigned long) in libsnappy.a(snappy.cc.o)
"operator new(unsigned long)", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"___cxa_allocate_exception", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"___cxa_begin_catch", referenced from:
___clang_call_terminate in libsnappy.a(snappy.cc.o)
"___cxa_free_exception", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"___cxa_pure_virtual", referenced from:
vtable for snappy::Sink in libsnappy.a(snappy-sinksource.cc.o)
vtable for snappy::Source in libsnappy.a(snappy-sinksource.cc.o)
"___cxa_throw", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"___gxx_personality_v0", referenced from:
snappy::GetUncompressedLength(snappy::Source*, unsigned int*) in libsnappy.a(snappy.cc.o)
snappy::Compress(snappy::Source*, snappy::Sink*) in libsnappy.a(snappy.cc.o)
snappy::RawUncompressToIOVec(char const*, unsigned long, iovec const*, unsigned long) in libsnappy.a(snappy.cc.o)
snappy::RawUncompressToIOVec(snappy::Source*, iovec const*, unsigned long) in libsnappy.a(snappy.cc.o)
snappy::RawUncompress(char const*, unsigned long, char*) in libsnappy.a(snappy.cc.o)
snappy::RawUncompress(snappy::Source*, char*) in libsnappy.a(snappy.cc.o)
snappy::Uncompress(char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) in libsnappy.a(snappy.cc.o)
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
您的 link 人似乎找不到 /usr/local/lib/libsnappy.a
。
尝试运行clang -Xlinker -v
,确保/usr/local/lib
存在于Library search paths
:
clang -Xlinker -v
@(#)PROGRAM:ld PROJECT:ld64-278.4
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
Library search paths:
/usr/lib
/usr/local/lib
通常,它会存在。然后尝试 sudo update_dyld_shared_cache
。
谈到调试 cmake
,您可以使用像 --debug-output
:
这样的标志
cmake --debug-output --trace --debug-trycompile ..
更新:
check_library_exists(snappy snappy_compress "" HAVE_SNAPPY)
实际执行如下操作,它将尝试link snappy
并查找函数是否存在:
cc -DCHECK_FUNCTION_EXISTS=snappy_compress -Wl,-search_paths_first -Wl,-headerpad_max_install_names -o check_snappy_exist CheckFunctionExists.c -lsnappy
CheckFunctionExists.c
的来源你可以找到here。
我认为这会简化问题。
我已经 end-up 安装 leveldb
和 brew
。同样重要的是将 XCode 中的路径添加到 User Header Search Paths
,屏幕如下:
我正在尝试在 mac os x high sierra 上构建 https://github.com/google/leveldb with support for https://github.com/google/snappy 压缩以供以后在 XCode 项目中使用,我正在完成标准编译过程两个项目的自述文件中都有描述。这包括通过 cmake
为两个项目构建项目。在 snappy
项目的情况下,过程很顺利,一切都可以完美地构建和安装。但是在 leveldb
的情况下,我无法让 cmake
找到我之前通过 make install
安装的 snappy
库。我不明白如何调试 cmake
并找到它查找库的位置。
感谢任何帮助。
以下是两个构建的结果:
编辑
这是一个输出,似乎 /usr/local/lib 在列表中
另一个编辑
我已经按照 sel-fish
提供的解决方案尝试了 运行 cc -DCHECK_FUNCTION_EXISTS=snappy_compress -Wl,-search_paths_first -Wl,-headerpad_max_install_names -o check_snappy_exist CheckFunctionExists.c -lsnappy
。但如果失败并显示以下输出:
Undefined symbols for architecture x86_64:
"std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"std::logic_error::logic_error(char const*)", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"std::length_error::~length_error()", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::resize(unsigned long, char)", referenced from:
snappy::Uncompress(char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) in libsnappy.a(snappy.cc.o)
snappy::Compress(char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) in libsnappy.a(snappy.cc.o)
"std::terminate()", referenced from:
___clang_call_terminate in libsnappy.a(snappy.cc.o)
"typeinfo for std::length_error", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"vtable for __cxxabiv1::__class_type_info", referenced from:
typeinfo for snappy::Sink in libsnappy.a(snappy-sinksource.cc.o)
typeinfo for snappy::Source in libsnappy.a(snappy-sinksource.cc.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for __cxxabiv1::__si_class_type_info", referenced from:
typeinfo for snappy::ByteArraySource in libsnappy.a(snappy-sinksource.cc.o)
typeinfo for snappy::UncheckedByteArraySink in libsnappy.a(snappy-sinksource.cc.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for std::length_error", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"operator delete[](void*)", referenced from:
snappy::Compress(snappy::Source*, snappy::Sink*) in libsnappy.a(snappy.cc.o)
snappy::SnappySinkAllocator::Deleter(void*, char const*, unsigned long) in libsnappy.a(snappy.cc.o)
"operator delete(void*)", referenced from:
snappy::UncompressAsMuchAsPossible(snappy::Source*, snappy::Sink*) in libsnappy.a(snappy.cc.o)
snappy::Uncompress(snappy::Source*, snappy::Sink*) in libsnappy.a(snappy.cc.o)
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
snappy::ByteArraySource::~ByteArraySource() in libsnappy.a(snappy-sinksource.cc.o)
snappy::UncheckedByteArraySink::~UncheckedByteArraySink() in libsnappy.a(snappy-sinksource.cc.o)
"operator new[](unsigned long)", referenced from:
snappy::internal::WorkingMemory::GetHashTable(unsigned long, int*) in libsnappy.a(snappy.cc.o)
snappy::Compress(snappy::Source*, snappy::Sink*) in libsnappy.a(snappy.cc.o)
snappy::SnappyScatteredWriter<snappy::SnappySinkAllocator>::SlowAppend(char const*, unsigned long) in libsnappy.a(snappy.cc.o)
"operator new(unsigned long)", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"___cxa_allocate_exception", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"___cxa_begin_catch", referenced from:
___clang_call_terminate in libsnappy.a(snappy.cc.o)
"___cxa_free_exception", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"___cxa_pure_virtual", referenced from:
vtable for snappy::Sink in libsnappy.a(snappy-sinksource.cc.o)
vtable for snappy::Source in libsnappy.a(snappy-sinksource.cc.o)
"___cxa_throw", referenced from:
void std::__1::vector<snappy::SnappySinkAllocator::Datablock, std::__1::allocator<snappy::SnappySinkAllocator::Datablock> >::__push_back_slow_path<snappy::SnappySinkAllocator::Datablock const>(snappy::SnappySinkAllocator::Datablock const&) in libsnappy.a(snappy.cc.o)
void std::__1::vector<char*, std::__1::allocator<char*> >::__push_back_slow_path<char* const>(char* const&) in libsnappy.a(snappy.cc.o)
"___gxx_personality_v0", referenced from:
snappy::GetUncompressedLength(snappy::Source*, unsigned int*) in libsnappy.a(snappy.cc.o)
snappy::Compress(snappy::Source*, snappy::Sink*) in libsnappy.a(snappy.cc.o)
snappy::RawUncompressToIOVec(char const*, unsigned long, iovec const*, unsigned long) in libsnappy.a(snappy.cc.o)
snappy::RawUncompressToIOVec(snappy::Source*, iovec const*, unsigned long) in libsnappy.a(snappy.cc.o)
snappy::RawUncompress(char const*, unsigned long, char*) in libsnappy.a(snappy.cc.o)
snappy::RawUncompress(snappy::Source*, char*) in libsnappy.a(snappy.cc.o)
snappy::Uncompress(char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) in libsnappy.a(snappy.cc.o)
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
您的 link 人似乎找不到 /usr/local/lib/libsnappy.a
。
尝试运行clang -Xlinker -v
,确保/usr/local/lib
存在于Library search paths
:
clang -Xlinker -v
@(#)PROGRAM:ld PROJECT:ld64-278.4
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
Library search paths:
/usr/lib
/usr/local/lib
通常,它会存在。然后尝试 sudo update_dyld_shared_cache
。
谈到调试 cmake
,您可以使用像 --debug-output
:
cmake --debug-output --trace --debug-trycompile ..
更新:
check_library_exists(snappy snappy_compress "" HAVE_SNAPPY)
实际执行如下操作,它将尝试link snappy
并查找函数是否存在:
cc -DCHECK_FUNCTION_EXISTS=snappy_compress -Wl,-search_paths_first -Wl,-headerpad_max_install_names -o check_snappy_exist CheckFunctionExists.c -lsnappy
CheckFunctionExists.c
的来源你可以找到here。
我认为这会简化问题。
我已经 end-up 安装 leveldb
和 brew
。同样重要的是将 XCode 中的路径添加到 User Header Search Paths
,屏幕如下: