Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static build does not link on MacOS Silicon #12621

Closed
lesterfernandez opened this issue May 5, 2024 · 3 comments
Closed

Static build does not link on MacOS Silicon #12621

lesterfernandez opened this issue May 5, 2024 · 3 comments

Comments

@lesterfernandez
Copy link

lesterfernandez commented May 5, 2024

Note: Please use Issues only for bug reports. For questions, discussions, feature requests, etc. post to dev group: https://groups.google.com/forum/#!forum/rocksdb or https://www.facebook.com/groups/rocksdb.dev

Expected behavior

The following command:
c++ -std=c++17 -I../rocksdb/include/ -L../rocksdb/ trace_test.cc -lrocksdb -o trace_test
when given a file named trace_test.cc with contents

#include <iostream>
#include "rocksdb/db.h"

int main() {
    rocksdb::DB* db;
    rocksdb::Options options;
    options.create_if_missing = true;
    rocksdb::Status status = rocksdb::DB::Open(options, "/tmp/testdb", &db);
    std::cout << "hello world! " << status.ok() << std::endl;
}

and the rocksdb repository in the parent directory, with make static_lib having been ran,
should result in a successful compilation and linkage.

Actual behavior

The following error message is produced:

Undefined symbols for architecture arm64:
  "_BZ2_bzCompress", referenced from:
      rocksdb::BZip2_Compress(rocksdb::CompressionInfo const&, unsigned int, char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*) in librocksdb.a[10](compressed_secondary_cache.o)
  "_BZ2_bzCompressEnd", referenced from:
      rocksdb::BZip2_Compress(rocksdb::CompressionInfo const&, unsigned int, char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*) in librocksdb.a[10](compressed_secondary_cache.o)
  "_BZ2_bzCompressInit", referenced from:
      rocksdb::BZip2_Compress(rocksdb::CompressionInfo const&, unsigned int, char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*) in librocksdb.a[10](compressed_secondary_cache.o)
  "_BZ2_bzDecompress", referenced from:
      rocksdb::BZip2_Uncompress(char const*, unsigned long, unsigned long*, unsigned int, rocksdb::MemoryAllocator*) in librocksdb.a[10](compressed_secondary_cache.o)
      rocksdb::BZip2_Uncompress(char const*, unsigned long, unsigned long*, unsigned int, rocksdb::MemoryAllocator*) in librocksdb.a[10](compressed_secondary_cache.o)
  "_BZ2_bzDecompressEnd", referenced from:
      rocksdb::BZip2_Uncompress(char const*, unsigned long, unsigned long*, unsigned int, rocksdb::MemoryAllocator*) in librocksdb.a[10](compressed_secondary_cache.o)
      rocksdb::BZip2_Uncompress(char const*, unsigned long, unsigned long*, unsigned int, rocksdb::MemoryAllocator*) in librocksdb.a[10](compressed_secondary_cache.o)
  "_BZ2_bzDecompressInit", referenced from:
      rocksdb::BZip2_Uncompress(char const*, unsigned long, unsigned long*, unsigned int, rocksdb::MemoryAllocator*) in librocksdb.a[10](compressed_secondary_cache.o)
  "_deflate", referenced from:
      rocksdb::Zlib_Compress(rocksdb::CompressionInfo const&, unsigned int, char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*) in librocksdb.a[10](compressed_secondary_cache.o)
  "_deflateBound", referenced from:
      rocksdb::Zlib_Compress(rocksdb::CompressionInfo const&, unsigned int, char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*) in librocksdb.a[10](compressed_secondary_cache.o)
  "_deflateEnd", referenced from:
      rocksdb::Zlib_Compress(rocksdb::CompressionInfo const&, unsigned int, char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*) in librocksdb.a[10](compressed_secondary_cache.o)
  "_deflateInit2_", referenced from:
      rocksdb::Zlib_Compress(rocksdb::CompressionInfo const&, unsigned int, char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*) in librocksdb.a[10](compressed_secondary_cache.o)
  "_deflateSetDictionary", referenced from:
      rocksdb::Zlib_Compress(rocksdb::CompressionInfo const&, unsigned int, char const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*) in librocksdb.a[10](compressed_secondary_cache.o)
  "_inflate", referenced from:
      rocksdb::Zlib_Uncompress(rocksdb::UncompressionInfo const&, char const*, unsigned long, unsigned long*, unsigned int, rocksdb::MemoryAllocator*, int) in librocksdb.a[10](compressed_secondary_cache.o)
      rocksdb::Zlib_Uncompress(rocksdb::UncompressionInfo const&, char const*, unsigned long, unsigned long*, unsigned int, rocksdb::MemoryAllocator*, int) in librocksdb.a[10](compressed_secondary_cache.o)
  "_inflateEnd", referenced from:
      rocksdb::Zlib_Uncompress(rocksdb::UncompressionInfo const&, char const*, unsigned long, unsigned long*, unsigned int, rocksdb::MemoryAllocator*, int) in librocksdb.a[10](compressed_secondary_cache.o)
      rocksdb::Zlib_Uncompress(rocksdb::UncompressionInfo const&, char const*, unsigned long, unsigned long*, unsigned int, rocksdb::MemoryAllocator*, int) in librocksdb.a[10](compressed_secondary_cache.o)
  "_inflateInit2_", referenced from:
      rocksdb::Zlib_Uncompress(rocksdb::UncompressionInfo const&, char const*, unsigned long, unsigned long*, unsigned int, rocksdb::MemoryAllocator*, int) in librocksdb.a[10](compressed_secondary_cache.o)
  "_inflateSetDictionary", referenced from:
      rocksdb::Zlib_Uncompress(rocksdb::UncompressionInfo const&, char const*, unsigned long, unsigned long*, unsigned int, rocksdb::MemoryAllocator*, int) in librocksdb.a[10](compressed_secondary_cache.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Steps to reproduce the behavior (MacOS Silicon)

  1. Clone the rocksdb directory and build the project using make static_lib
  2. Make a sibling directory and inside write the program given above
  3. Attempt to compile the program while providing the proper include and library arguments
@alanpaxton
Copy link
Contributor

Hi @lesterfernandez I think you meant make static_lib ?

There are targets in the rocksb Makefile for libbz2.a and libz.a
If you make libbz2.a and make libz.a first, then
c++ -std=c++17 -I../rocksdb-evolved/include/ -L../rocksdb/ trace_test.cc -lrocksdb -lbz2 -lz -o trace_test
your build should work

I'm not entirely sure why Rocks defaults to requiring that these compression types are available. Do you know @adamretter ?

@adamretter
Copy link
Collaborator

I'm not entirely sure why Rocks defaults to requiring that these compression types are available

@alanpaxton I think if I recall correctly, the build for RocksDB expects those to be available as RocksDB offers them for block compression.

@lesterfernandez
Copy link
Author

@alanpaxton You were right, I needed to run make for the libbz2.a and libz.a targets and then link them to my program.
Since the static build of rocksdb on MacOS does function, I will close the issue.

However, I think it would be valuable for INSTALL.md to mention this requirement in the MacOS section. Note: I was getting the same issue even when trying to link with rocksdb from the homebrew installation. Most of the other OS sections give guidance on how to satisfy the compression library requirement (by installing the libraries through a package manager).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants