代码之家  ›  专栏  ›  技术社区  ›  Lu4

无法使用snappy支持编译leveldb

  •  2
  • Lu4  · 技术社区  · 6 年前

    我正在努力建造 https://github.com/google/leveldb 支持 https://github.com/google/snappy 在mac os x high sierra上进行压缩,以便以后在XCode项目中使用,我正在浏览自述文件中描述的两个项目的标准编译过程。这包括通过 cmake 对于这两个项目。如果 snappy 项目流程顺畅,所有构建和安装都完美无缺。但是,如果 leveldb ,我做不到 cmake公司 发现 精炼的 我以前通过安装的库 make install 。我不知道如何调试 cmake公司 并找到它寻找图书馆的地方。

    非常感谢您的帮助。

    以下是两个构建的结果: enter image description here enter image description here


    编辑

    这是一个输出,似乎列表中有/usr/local/lib

    enter image description here

    enter image description here

    enter image description here


    另一个编辑

    我试过跑步 cc -DCHECK_FUNCTION_EXISTS=snappy_compress -Wl,-search_paths_first -Wl,-headerpad_max_install_names -o check_snappy_exist CheckFunctionExists.c -lsnappy 根据提供的解决方案 sel-fish 。但如果出现以下输出失败:

    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)
    
    2 回复  |  直到 6 年前
        1
  •  2
  •   sel-fish    6 年前

    似乎您的链接器找不到 /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)
    

    实际执行以下操作,它将尝试链接 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
    我认为这将简化问题。

        2
  •  1
  •   Lu4    6 年前

    我最终安装了 leveldb 具有 brew 。同样重要的是将XCode中的路径添加到 User Header Search Paths ,屏幕如下:

    enter image description here enter image description here