apache / apache/brpc

[cmake] 使用leveldb提供的cmake配置文件来查找并使用leveldb

Open
#1,691 3 comments 0 reactions 0 assignees View on GitHub
kind/compile
Dominant language
C++
Stars
17.6k
Forks
4.1k
Avg merge
2d 12h
Merged PRs (30d)
69

Description

**Describe the bug (描述bug)**
Hi 各位,
我是vcpkg维护者。
这段时间我们收到了一个brpc的build失败问题 ( https://github.com/microsoft/vcpkg/issues/22962 ):
```
[328/338] : && /usr/bin/c++ -DBRPC_WITH_GLOG=1 -DGFLAGS_NS=google -DBTHREAD_USE_FAST_PTHREAD_MUTEX -D__const__= -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DBRPC_REVISION=\"0.9.7\|master\|7e7dad5fe\|2022-02-04T18:00:26-08:00\" -D__STRICT_ANSI__ -g -DENABLE_THRIFT_FRAMED_PROTOCOL -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer -msse4 -msse4.2 -Wno-aligned-new -DNDEBUG -g -rdynamic src/CMakeFiles/protoc-gen-mcpack.dir/mcpack2pb/generator.cpp.o -o output/bin/protoc-gen-mcpack -Wl,-rpath,/mnt/c/dev/vcpkg-dev/vcpkg/buildtrees/brpc/x64-linux-dbg/output/lib output/lib/libbrpc.so /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/lib/libgflags.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libprotobufd.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libleveldb.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/lib/libprotoc.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libcrypto.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libthriftd.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/lib/libssl.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/lib/libcrypto.a -lpthread -lpthread /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libssl.a -lz /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libssl.a -lz -ldl /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libglog.a -lrt /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libglog.a -lrt && :
FAILED: output/bin/protoc-gen-mcpack
: && /usr/bin/c++ -DBRPC_WITH_GLOG=1 -DGFLAGS_NS=google -DBTHREAD_USE_FAST_PTHREAD_MUTEX -D__const__= -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DBRPC_REVISION=\"0.9.7\|master\|7e7dad5fe\|2022-02-04T18:00:26-08:00\" -D__STRICT_ANSI__ -g -DENABLE_THRIFT_FRAMED_PROTOCOL -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer -msse4 -msse4.2 -Wno-aligned-new -DNDEBUG -g -rdynamic src/CMakeFiles/protoc-gen-mcpack.dir/mcpack2pb/generator.cpp.o -o output/bin/protoc-gen-mcpack -Wl,-rpath,/mnt/c/dev/vcpkg-dev/vcpkg/buildtrees/brpc/x64-linux-dbg/output/lib output/lib/libbrpc.so /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/lib/libgflags.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libprotobufd.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libleveldb.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/lib/libprotoc.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libcrypto.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libthriftd.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/lib/libssl.a /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/lib/libcrypto.a -lpthread -lpthread /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libssl.a -lz /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libssl.a -lz -ldl /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libglog.a -lrt /mnt/c/dev/vcpkg-dev/vcpkg/installed/x64-linux/debug/lib/libglog.a -lrt && :
/usr/bin/ld: output/lib/libbrpc.so: undefined reference to `snappy::RawCompress(char const*, unsigned long, char*, unsigned long*)'
/usr/bin/ld: output/lib/libbrpc.so: undefined reference to `snappy::RawUncompress(char const*, unsigned long, char*)'
/usr/bin/ld: output/lib/libbrpc.so: undefined reference to `snappy::GetUncompressedLength(char const*, unsigned long, unsigned long*)'
/usr/bin/ld: output/lib/libbrpc.so: undefined reference to `snappy::MaxCompressedLength(unsigned long)'
collect2: error: ld returned 1 exit status
```
经过深入调查,我发现这是因为leveldb查找到的snappy是系统中的,而不是vcpkg自带的,所以我修复了它( https://github.com/microsoft/vcpkg/pull/23048 )。
然而,由于brpc依赖于leveldb,我仍然需要去修复brpc中查找并使用leveldb的cmake代码:切换`find_path`与`find_library`至`find_package`并修复使用的地方`target_link_libraries`。
但是很遗憾,我发现将依赖库写入pkgconfig中的方式居然是硬编码,这导致了我即使修复生成配置文件中的leveldb, pkgconfig中`LIBS.PRIVATE`的值也不能被修复。
所以我认为brpc需要更新一下cmake代码了:由于brpc无法感知leveldb依赖了哪些库,所以brpc必须严格遵循leveldb提供的cmake配置文件`leveldbConfig.cmake`以及`leveldb.pc`(如果有的话)。

**Expected behavior (期望行为)**
`brpc.pc`中的`LIBS.PRIVATE`应当包含完整的依赖链。

**Versions (各种版本)**
OS: ALL
Compiler: ALL
brpc: 0.9.7
protobuf: 不涉及

**Additional context/screenshots (更多上下文/截图)**

Contributor guide

Open the contributing guide

Research direction

Start by inspecting the CMake code that currently uses find_path and find_library for LevelDB, then compare it with leveldbConfig.cmake and leveldb.pc. Trace the target_link_libraries usage and generated brpc.pc so the LIBS.PRIVATE value preserves LevelDB's complete dependency chain; verify against the reported vcpkg build failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.