facebook / rocksdb

A library that provides an embeddable, persistent key-value store for fast storage.
http://rocksdb.org
GNU General Public License v2.0
28.65k stars 6.33k forks source link

pkg-config file causes build errors #8286

Open michaelkuhn opened 3 years ago

michaelkuhn commented 3 years ago

The pkg-config file that recently started being generated by RocksDB contains flags that make it hard to use on different systems/compilers/etc.

Expected behavior

The pkg-config file should work on all systems as well as with C and C++.

Actual behavior

Trying to use RocksDB in a C application results in errors like this:

cc1: error: command-line option '-std=c++11' is valid for C++/ObjC++ but not for C [-Werror]
cc1: error: command-line option '-faligned-new=1' is valid for C++/ObjC++ but not for C [-Werror]
cc1: error: third-party/gtest-1.8.1/fused-src: No such file or directory [-Werror=missing-include-dirs]
cc1: error: ./third-party/folly: No such file or directory [-Werror=missing-include-dirs]

Clang also does not know about some of the flags:

error: unknown warning option '-Werror=deprecated-copy'; did you mean '-Werror=deprecated'? [-Werror,-Wunknown-warning-option]
error: invalid argument '-std=c++11' not allowed with 'C'

The generated one causing problems looks something like this:

prefix=$SPACK/opt/spack/linux-fedora34-zen2/gcc-11.1.1/rocksdb-6.19.3-dd5zq7iizz54mqxivkpm74mvbbuhxmbn
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=$SPACK/opt/spack/linux-fedora34-zen2/gcc-11.1.1/rocksdb-6.19.3-dd5zq7iizz54mqxivkpm74mvbbuhxmbn/lib

Name: rocksdb
Description: An embeddable persistent key-value store for fast storage
Version: 6.19.3
Libs: -L${libdir}  -ldl -Wl,-rpath -Wl, -lrocksdb
Libs.private: -lpthread -lrt -ldl -lgflags -lz -llz4 
Cflags: -I${includedir} -std=c++11  -faligned-new -DHAVE_ALIGNED_NEW -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -Wno-error=deprecated-copy -Wno-error=pessimizing-move -Wno-error=redundant-move -I$SPACK/opt/spack/linux-fedora34-zen2/gcc-11.1.1/zlib-1.2.11-4ymlsgm3l63qbi5tliaeop2xpppaci2b/include -I$SPACK/opt/spack/linux-fedora34-zen2/gcc-11.1.1/lz4-1.9.3-bpkgu6gpnzshfjdbc2qvd2f5m6aisqas/include -I$SPACK/opt/spack/linux-fedora34-zen2/gcc-11.1.1/gflags-2.2.2-gy6ezqt56zhofysz2wmr4w47qi4cjqip/include -DOS_LINUX -fno-builtin-memcmp -DROCKSDB_FALLOCATE_PRESENT -DGFLAGS=1 -DZLIB -DLZ4 -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_PTHREAD_ADAPTIVE_MUTEX -DROCKSDB_BACKTRACE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -DROCKSDB_AUXV_GETAUXVAL_PRESENT    -DHAVE_SSE42  -DHAVE_PCLMUL  -DHAVE_AVX2  -DHAVE_BMI  -DHAVE_LZCNT -DHAVE_UINT128_EXTENSION -DROCKSDB_SUPPORT_THREAD_LOCAL  -isystem third-party/gtest-1.8.1/fused-src -isystem ./third-party/folly

A working one generated by Spack or Fedora looks like this:

prefix=$SPACK/opt/spack/linux-ubuntu18.04-westmere/gcc-9.3.0/rocksdb-6.11.4-rsjvyzatxw7pfy2aurjozt3jv54hovka
exec_prefix=${prefix}
libdir=$SPACK/opt/spack/linux-ubuntu18.04-westmere/gcc-9.3.0/rocksdb-6.11.4-rsjvyzatxw7pfy2aurjozt3jv54hovka/lib
includedir=$SPACK/opt/spack/linux-ubuntu18.04-westmere/gcc-9.3.0/rocksdb-6.11.4-rsjvyzatxw7pfy2aurjozt3jv54hovka/include

Name: rocksdb
Description: RocksDB: A Persistent Key-Value Store for Flash and RAM Storage
Version: 6.11.4
Cflags: -I${includedir}
Libs: -L${libdir} -lrocksdb -ldl

Steps to reproduce the behavior

Try to use recent release of RocksDB from C and/or with Clang.

michaelkuhn commented 3 years ago

I found another problem with the pkg-config file: Due to escaping issues, '$ORIGIN' does not end up in the pkg-config file, resulting in something like -ldl -Wl,-rpath -Wl, -lrocksdb. This will cause build errors with Clang because it tries to consume the next argument if the argument to -Wl is empty (see also https://github.com/mesonbuild/meson/issues/2814).

We use the following patch in Spack to fix these issues, feel free to reuse: https://github.com/spack/spack/blob/develop/var/spack/repos/builtin/packages/rocksdb/pkg-config.patch

shanoaice commented 1 year ago

I am also troubled by this, since the exported pkg-config cflags contains -std=c++17 which overrides -std=c++20 specified by my build system, causing failure.