brpc icon indicating copy to clipboard operation
brpc copied to clipboard

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

Open JackBoosY opened this issue 3 years ago • 3 comments

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_pathfind_libraryfind_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 (更多上下文/截图)

JackBoosY avatar Feb 11 '22 09:02 JackBoosY

hit the same question on version 1.0.0:

../output/lib/libbrpc.so: undefined reference to `snappy::GetUncompressedLength(char const*, unsigned long, unsigned long*)'
../output/lib/libbrpc.so: undefined reference to `snappy::MaxCompressedLength(unsigned long)'
../output/lib/libbrpc.so: undefined reference to `snappy::RawUncompress(char const*, unsigned long, char*)'
../output/lib/libbrpc.so: undefined reference to `snappy::RawCompress(char const*, unsigned long, char*, unsigned long*)'
collect2: error: ld returned 1 exit status
make[2]: *** [output/bin/protoc-gen-mcpack] Error 1
make[1]: *** [src/CMakeFiles/protoc-gen-mcpack.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
^Cmake[2]: make[2]: make[2]: make[2]: make[2]: *** Deleting file `output/bin/rpc_press'*** Deleting file `output/bin/rpc_replay'*** Deleting file `output/bin/trackme_server'*** Deleting file `output/bin/parallel_http'

helifu avatar May 26 '22 08:05 helifu

hit the same question on version 1.0.0:

../output/lib/libbrpc.so: undefined reference to `snappy::GetUncompressedLength(char const*, unsigned long, unsigned long*)'
../output/lib/libbrpc.so: undefined reference to `snappy::MaxCompressedLength(unsigned long)'
../output/lib/libbrpc.so: undefined reference to `snappy::RawUncompress(char const*, unsigned long, char*)'
../output/lib/libbrpc.so: undefined reference to `snappy::RawCompress(char const*, unsigned long, char*, unsigned long*)'
collect2: error: ld returned 1 exit status
make[2]: *** [output/bin/protoc-gen-mcpack] Error 1
make[1]: *** [src/CMakeFiles/protoc-gen-mcpack.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
^Cmake[2]: make[2]: make[2]: make[2]: make[2]: *** Deleting file `output/bin/rpc_press'*** Deleting file `output/bin/rpc_replay'*** Deleting file `output/bin/trackme_server'*** Deleting file `output/bin/parallel_http'

Fixed by a manual operation.

helifu avatar May 26 '22 08:05 helifu

#1799 may solve this problem

wwbmmm avatar Jun 20 '22 02:06 wwbmmm