tangtang5156 opened a new issue, #2266: URL: https://github.com/apache/brpc/issues/2266
**Describe the bug (描述bug)** 运行可执行文件时报错symbol lookup error: /usr/local/lib/libbrpc.so: undefined symbol: pthread_mutex_lock **To Reproduce (复现方法)** 尝试多种使用方法,发现在如下场景下可复现报错: **1、编译产出libhttpserver.so(使用c++开发),该so依赖brpc**,cmake选项如下: set(DYNAMIC_LIB # ${CMAKE_THREAD_LIBS_INIT} ${GFLAGS_LIBRARY} ${PROTOBUF_LIBRARIES} ${LEVELDB_LIB} ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY} # ${THRIFT_LIB} # ${THRIFTNB_LIB} dl ) TARGET_LINK_LIBRARIES(httpserver proto brpc ${DYNAMIC_LIB} pthread) (此时直接使用httpserver链接到其他可执行文件时不会报错) **2、产出B.so(使用c开发),B.so使用到了httpserver中的功能**,故依赖了httpserver.so,cmake选项如下: ADD_LIBRARY(B SHARED jiangdan.c) TARGET_LINK_LIBRARIES(B httpserver) **3、产出可执行文件main(使用c开发),main中使用到了B.so的功能**,故依赖了B.so,同时C中使用到了pthread的功能,也依赖了pthread,cmake选项如下(已经将B放在pthread的前面): ADD_EXECUTABLE(main main.c) TARGET_LINK_LIBRARIES(main B pthread) 4、此时编译项目即cmake ..&& make结果正常,但是运行main时会报错: symbol lookup error: /usr/local/lib/libbrpc.so: undefined symbol: pthread_mutex_lock **Expected behavior (期望行为)** 测试过程发现,若可执行文件直接依赖httpserver和pthread时不会报错,可正常运行;但是只要中间再多层依赖,这种方式就会报错。但是项目依赖方很多,其他项目均是依赖httpserver做二次so的开发,无法规避多层依赖问题。 预期:执行main时可正常执行。不管是通过链接静态brpc还是动态brpc,只要有解决方式即可。 **已排查了多天无果,紧急求助。** **Versions (各种版本)** OS: linux ubuntu Compiler: brpc: 尝试了几个版本包括最新的1.5.0均会报错 protobuf: **Additional context/screenshots (更多上下文/截图)** 其他尝试的解决方案,比如动态brpc改为静态brpc,过程如下: 1、为解决上述问题,尝试将httpserver链接静态brpc,如: TARGET_LINK_LIBRARIES(httpserver proto libbrpc.a ${DYNAMIC_LIB} pthread) 修改后再重新执行main,不再提示brpc缺失,而是提示依赖libbrpc.a的httpserver.so缺失: symbol lookup error: /usr/local/lib/libhttpserver: undefined symbol: pthread_mutex_lock 2、为解决问题1,则尝试将brpc.a的所有符号均链接进来,如 TARGET_LINK_LIBRARIES(httpserver proto "-Wl,--whole-archive" libbrpc.a "-Wl,--no-whole-archive" ${DYNAMIC_LIB} pthread) 修改后再重新执行main,代码直接段错误崩溃,debug后发现崩溃点在于如下图:   -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org